To begin with, what is B in the line with the operator is unknown.
Further, the cast operator has no return type (it is already specified in the operator!), And does not receive any parameter - it already receives this ...
Member int B; in class B also not good.
Coercion b=(B*)a will not even try to use your operator - because this is a pointer casting to a pointer (in parentheses - terrible: a pointer to the base class to a pointer to the derived ...)
So the best you can get is about
class B; class A { protected: int a; public: operator B*() { throw("Bad Type Overload"); } }; class B:public A { protected: int b; }; int main() { A *a; (B*)*a; return 0; }
but all this is not a very healthy occupation, and it is not clear to whom and why it is necessary ...
Update
Here, take a look - you can get an exception, but when bringing links.
#include <iostream> using namespace std; class Base { public: virtual ~Base() {} }; class Derived: public Base { public: virtual ~Derived() {} }; int main() { Base * b = new Base; Derived * d = dynamic_cast<Derived *>(b); cout << d << endl; try { Base bb; Derived & dd = dynamic_cast<Derived &>(bb); } catch(exception&e) { cout << e.what() << endl; } }