J
jared.grubb
Can a private Base class method convert to/from a Derived* using
static_cast? The CPL book says that a Derived method is allowed to
convert to/from Base, but says nothing about whether a Base method may
do the same thing.
My embedded compiler and g++ disagree on whether this is legal.
Example:
class Base { public: void foo(); };
class Derived : private Base { public: void foo(); };
void Base::foo() {
static_cast<Base*>((Derived*)0); // ok in g++, but legal?
static_cast<Derived*>((Base*)0); // ok in g++, but legal?
}
void Derived::foo() {
static_cast<Base*>((Derived*)0); // legal
static_cast<Derived*>((Base*)0); // legal
}
int main()
{
static_cast<Base*>((Derived*)0); // illegal
static_cast<Derived*>((Base*)0); // illegal
return 0;
}
static_cast? The CPL book says that a Derived method is allowed to
convert to/from Base, but says nothing about whether a Base method may
do the same thing.
My embedded compiler and g++ disagree on whether this is legal.
Example:
class Base { public: void foo(); };
class Derived : private Base { public: void foo(); };
void Base::foo() {
static_cast<Base*>((Derived*)0); // ok in g++, but legal?
static_cast<Derived*>((Base*)0); // ok in g++, but legal?
}
void Derived::foo() {
static_cast<Base*>((Derived*)0); // legal
static_cast<Derived*>((Base*)0); // legal
}
int main()
{
static_cast<Base*>((Derived*)0); // illegal
static_cast<Derived*>((Base*)0); // illegal
return 0;
}