नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
cannot use casting_operator to convert from 'type1' to 'type2'
Remarks
A casting operator tried to convert between incompatible types. For example, you cannot use the dynamic_cast operator to convert a pointer to a reference. The dynamic_cast operator cannot be used to cast away qualifiers. All qualifiers on the types must match.
You can use the const_cast operator to remove attributes such as const, volatile, or __unaligned.
Examples
The following example generates C2682:
// C2682.cpp
class A { virtual void f(); };
class B: public A {};
void g(A* pa) {
B& rb = dynamic_cast<B&>(pa); // C2682
}
The following example generates C2682:
// C2682b.cpp
// compile with: /clr
ref struct R{};
ref struct RR : public R{};
ref struct H {
RR^ r ;
short s;
int i;
};
int main() {
H^ h = gcnew H();
interior_ptr<int>lr = &(h->i);
interior_ptr<short>ssr = safe_cast<interior_ptr<short> >(lr); // C2682
interior_ptr<short>ssr = reinterpret_cast<interior_ptr<short> >(lr); // OK
}