Re: Multi Inheritance
* Ali Karaali:
Hello group !
I have a class interface (as .h ) but i don't have this class's source
file (as .cpp ). So i can't reach the source file..
class ServerBase {
public :
virtual void vfunc() const;
void nvfunc() const;
~ServerBase();
};
class ServerDer : public ServerBase {
public :
void vfunc() const;
~ServerDer();
};
I want to make nvfunc() and ~ServerBase functions virtual. how can i
do that?
You can't. That is, you can't make the existing code call your nvfunc()
implementation. But you can obtain that effect for your own code, by
wrapping the class, e.g.
class MyServerBase
{
private:
virtual ServerBase& impl() = 0;
public:
virtual ~MyServerBase() {}
virtual void nvfunc() const { impl().nvfunc(); }
};
class MyServerDer: public MyServeBase
{
private:
ServerDer myImpl;
ServerDer& impl() { return myImpl; }
public:
virtual void nvfunc() cosnt { ... }
...
};
But the question is why would you want to do that.
Presumably what nvfunc does is to wrap vfunc with some precondition and
postcondition checking, not to be overridden by you.
It's could be bad design not to have the ServerBase destructor virtual,
yes, but presumably these classes are designed to be used via smart
pointers that ensure destruction via pointer to most derived.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?