* Erik Rydgren <[EMAIL PROTECTED]> [2002-12-13 17:07]:
> The performance hit comes from larger vtables that needs to be set at object
> creation. After that...
And I think there should not even be a larger vtable. Ideally,
to avoid inconsistencies between the const and non-const variants,
the implementation could be:
class X;
class Base {
public:
virtual X const* foo() const;
inline X* foo();
private:
X* myX_;
};
inline X* BaseClass::foo()
{
BaseClass const& self(*this);
// We know that const_cast is ok here since "this" is a pointer
// to non-const
return const_cast<X*>(self.foo());
}
class Derived {
public:
// override only the const variant
virtual X const* foo() const;
// ...
};
Unfortunately, this would break a lot of code when the virtual foo()
is the non-const variant at the moment. So maybe the other way would
have to be taken (leave the non-const foo() virtual and provide a
const inline function in the base class). However, this approach is
IMHO not as secure as the variant above...
--
Ingolf Steinbach Jena-Optronik GmbH
[EMAIL PROTECTED] ++49 3641 200-147
PGP: 0x7B3B5661 213C 828E 0C92 16B5 05D0 4D5B A324 EC04
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]