I
Immortal Nephi
The rule of inheritance states that you define from top to bottom.
Sometimes, you want to define base class and set reference from
dervied class to base class, but you violate the rule.
Here is an example of my code below.
class A {};
class B : public A {};
int main(void)
{
// A a;
B &b = a; // Compiler cannot compile -- error
// B &b = reinterpret_cast<B&> ( a ); // OK
B b;
A &a = b; // OK
return 0;
}
Please state your opinion. Is it ok to violate the rule? is this
code portable to all different machines?
Nephi
Sometimes, you want to define base class and set reference from
dervied class to base class, but you violate the rule.
Here is an example of my code below.
class A {};
class B : public A {};
int main(void)
{
// A a;
B &b = a; // Compiler cannot compile -- error
// B &b = reinterpret_cast<B&> ( a ); // OK
B b;
A &a = b; // OK
return 0;
}
Please state your opinion. Is it ok to violate the rule? is this
code portable to all different machines?
Nephi