[linux-audio-dev] A C++ question
Niels A. Moseley
n.a.moseley at student.utwente.nl
Fri Apr 18 07:27:01 UTC 2003
Hi,
>Another, is when I am linking, it complains about the vtable and won't
>compile. This error leaves me baffled because usually the class compiled
>and ran before without any problems, and I didn't change it at all.
>
>class thisFooWillNotCompile
>{
>public:
>
> virtual void thisFooMakesMeAngry() = 0;
>};
>
>class thisFooIsNoGood : public thisFooWillNotCompile
>{
>public:
>
> void thisFooMakesMeAngry() { printf("I will not link I will say
>vtable blah blah blah and die..\n"); }
>};
>
>
>Sorry I am vague but, if I knew why this was happening, I would be an
>advanced C++ programmer.One of them appears to be an error in my code,
>but the way it manifests itself is weird.
You always need a virtual destructor in the class if you do inhertance.
Otherwise upon destruction of the derived class, the baseclass destructor
will not be called.
Cheers,
Niels.
so:
class thisFooWillNotCompile
{
public:
virtual ~thisFooWillNotCompile(); // ADD THIS!
virtual void thisFooMakesMeAngry() = 0;
};
class thisFooIsNoGood : public thisFooWillNotCompile
{
public:
virtual ~thisFooIsNoGood(); // ADD THIS!
void thisFooMakesMeAngry() { printf("I will not link I will say vtable
blah blah blah and die..\n"); }
};
More information about the Linux-audio-dev
mailing list