I just tried to define a pure virtual destructor in an abstract base class
and I got “Warning 621: Pure virtual destructors must have a definition”.
If it has a definition then it isn’t a “Pure” virtual destructor.
Any comments?
I just tried to define a pure virtual destructor in an abstract base class
and I got “Warning 621: Pure virtual destructors must have a definition”.
If it has a definition then it isn’t a “Pure” virtual destructor.
Any comments?
Are you getting the error at the reading of the .hpp file, or at the
declaration of an object of that class?
You probably cannot declare an instance of an object that has virtual
functions, you should be using a derived class that has an actual
declaration for that function.
Bill at Sierra Design <BC@SierraDesign.com> wrote in message
news:8o6clk$647$1@inn.qnx.com…
I just tried to define a pure virtual destructor in an abstract base class
and I got “Warning 621: Pure virtual destructors must have a definition”.If it has a definition then it isn’t a “Pure” virtual destructor.
Any comments?
Previously, Bill at Sierra Design wrote in qdn.public.qnx4:
I just tried to define a pure virtual destructor in an abstract base class
and I got “Warning 621: Pure virtual destructors must have a definition”.If it has a definition then it isn’t a “Pure” virtual destructor.
Not true, pure just means that the class is abstract until a derived class
defines this method.
You can’t have a class without a destructor. If you don’t declare one,
then the compiler give you a default one. You declared a destructor (you
declared it pure, but no matter…), thus the compiler will not give you
a default one, and you must define it yourself.
People don’t often define pure virtual functions, but since when
an object is destroyed, the destructors of all the base classes are
called the destructor is something of an exception.
Sam
–
Sam Roberts (sam@cogent.ca), Cogent Real-Time Systems (www.cogent.ca)
No. I am NOT trying to instanciate an instance of this class. I am getting
the error when the class is defined.
BTW. There is no *.hpp file. This is all happening in my all purpose test
file “t.cpp”.
Paul Russell <paul@jenosys.com> wrote in message
news:8o6j0a$8tb$1@inn.qnx.com…
Are you getting the error at the reading of the .hpp file, or at the
declaration of an object of that class?
You probably cannot declare an instance of an object that has virtual
functions, you should be using a derived class that has an actual
declaration for that function.Bill at Sierra Design <> BC@SierraDesign.com> > wrote in message
news:8o6clk$647$> 1@inn.qnx.com> …
I just tried to define a pure virtual destructor in an abstract base
class
and I got “Warning 621: Pure virtual destructors must have a
definition”.If it has a definition then it isn’t a “Pure” virtual destructor.
Any comments?
\
Hi Sam,
So . . . if I have
class myClass
{
public:
myClass() { yadda, yadda, ydaad; }
virtual ~myClass() {}
};
that’s as purely virtual as I can get?
Sam Roberts <sam@cogent.ca> wrote in message
news:Voyager.000828135450.16536A@sam.cogent.ca…
Previously, Bill at Sierra Design wrote in qdn.public.qnx4:
I just tried to define a pure virtual destructor in an abstract base
class
and I got “Warning 621: Pure virtual destructors must have a
definition”.If it has a definition then it isn’t a “Pure” virtual destructor.
Not true, pure just means that the class is abstract until a derived class
defines this method.You can’t have a class without a destructor. If you don’t declare one,
then the compiler give you a default one. You declared a destructor (you
declared it pure, but no matter…), thus the compiler will not give you
a default one, and you must define it yourself.People don’t often define pure virtual functions, but since when
an object is destroyed, the destructors of all the base classes are
called the destructor is something of an exception.Sam
–
Sam Roberts (> sam@cogent.ca> ), Cogent Real-Time Systems (> www.cogent.ca> )
Previously, Bill at Sierra Design wrote in qdn.public.qnx4:
Hi Sam,
So . . . if I have
class myClass
{
public:
myClass() { yadda, yadda, ydaad; }
virtual ~myClass() = 0;
};
myClass::~myClass() {}
that’s as purely virtual as I can get?
You can be as pure virtual as you want, but you STILL need to
define a dtor for your class. Pure virtual doesn’t mean it
doesn’t have a definition, it means that a derived class MUST
define it. This is different, even though the distinction usually
isn’t apparent, because if a derived class defines a function
thats declared pure in a base class, its usually the derived
classes function thats called, so its not noticeable that
there may be a definition for the base classes pure function.
Thats convoluted, sorry.
Anyhow:
class C {
virtual void f() = 0;
virtual ~C() = 0;
};
void C::f() {}
C::~C() {}
// C is abstract, derived classes must define f() before
// they can be instantiated, even though C has defined one
// as well. This is unusual, but legal.
class D : public C {
void f() {}
~D() {}
};
C* c = new D;
c->C::f();
Destructors are differenct because, when you call
delete c;
What happens is this:
D::~D() // because of the virtual, this is good and you always
// should declare dtors virtual for classes that will
// be deleted through a pointer to their base class
C::~C() // also good, because destructors ALWAYS go up the chain
// from most derived to base, in the opposite direction
// of ctors.
If you didn’t define ~C() you’d get a link error.
Hope that’s helpful. I can’t recall where I learned this, I think
from Scott Meyers excellent two books, which I think all c++ programmers
should read cover to cover.
Sam
Sam Roberts <> sam@cogent.ca> > wrote in message
news:> Voyager.000828135450.16536A@sam.cogent.ca> …
Previously, Bill at Sierra Design wrote in qdn.public.qnx4:
I just tried to define a pure virtual destructor in an abstract base
class
and I got “Warning 621: Pure virtual destructors must have a
definition”.If it has a definition then it isn’t a “Pure” virtual destructor.
Not true, pure just means that the class is abstract until a derived class
defines this method.You can’t have a class without a destructor. If you don’t declare one,
then the compiler give you a default one. You declared a destructor (you
declared it pure, but no matter…), thus the compiler will not give you
a default one, and you must define it yourself.People don’t often define pure virtual functions, but since when
an object is destroyed, the destructors of all the base classes are
called the destructor is something of an exception.Sam
–
Sam Roberts (> sam@cogent.ca> ), Cogent Real-Time Systems (> www.cogent.ca> )
\
–
Sam Roberts (sam@cogent.ca), Cogent Real-Time Systems (www.cogent.ca)