Ilia Faingold
May 16th, 1999, 12:56 PM
Hi all,
I have a question about C++ standard. According to [Stroustrup, C++ Programming Language, 3d ed., p.425], there is one case when the return type of overriding function may differ from the virtual function it overrides. Namely, if the original return type was B*, then the return type of the overriding function may be D*, if B is a public base of D.
In my programm I have three classes,
class Base
{
...
virtual Base* f() { return 0; }
...
}
class Derived1: public Base
{
...
}
class Derived2: public Derived1
{
...
Derived2* f() {...}
...
}
According to the standard (as far as I understand it), this should work. However, the Microsoft Visual C++ 6.0 compiler throws me error C2555. Where the truth?
Thank you for help,
Ilia.
I have a question about C++ standard. According to [Stroustrup, C++ Programming Language, 3d ed., p.425], there is one case when the return type of overriding function may differ from the virtual function it overrides. Namely, if the original return type was B*, then the return type of the overriding function may be D*, if B is a public base of D.
In my programm I have three classes,
class Base
{
...
virtual Base* f() { return 0; }
...
}
class Derived1: public Base
{
...
}
class Derived2: public Derived1
{
...
Derived2* f() {...}
...
}
According to the standard (as far as I understand it), this should work. However, the Microsoft Visual C++ 6.0 compiler throws me error C2555. Where the truth?
Thank you for help,
Ilia.