inaccessible typecast
-
Hello! I have two classes A and B, which is derived of A
class A {}; template<class T> class B : protected A { public: operator const A&() { return *this; } };
When I tryA a; B<int> b; a = b; //Error
I get the Error error C2243: 'type cast' : Konvertierung von 'class B *' zu 'const class A &' existiert bereits, aber es ist kein Zugriff darauf moeglich Why? I have defined an public conversion operator... Alex -
Hello! I have two classes A and B, which is derived of A
class A {}; template<class T> class B : protected A { public: operator const A&() { return *this; } };
When I tryA a; B<int> b; a = b; //Error
I get the Error error C2243: 'type cast' : Konvertierung von 'class B *' zu 'const class A &' existiert bereits, aber es ist kein Zugriff darauf moeglich Why? I have defined an public conversion operator... AlexYou defined a
const
conversion operator, but your assignment is to a non-const
l-value.
Software Zen:
delete this;
-
Hello! I have two classes A and B, which is derived of A
class A {}; template<class T> class B : protected A { public: operator const A&() { return *this; } };
When I tryA a; B<int> b; a = b; //Error
I get the Error error C2243: 'type cast' : Konvertierung von 'class B *' zu 'const class A &' existiert bereits, aber es ist kein Zugriff darauf moeglich Why? I have defined an public conversion operator... AlexLionAM wrote:
public: operator const A&() { return *this; }
create two operators, one const, one not :
template<class T> class B : protected A {
public:
operator const A&() const { return *this; }
operator A&() { return *this; }
};
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
LionAM wrote:
public: operator const A&() { return *this; }
create two operators, one const, one not :
template<class T> class B : protected A {
public:
operator const A&() const { return *this; }
operator A&() { return *this; }
};
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]