Dan Mattsson
2009-11-11 09:25:03 UTC
I've been searching for a solution (or, rather, the reason) for an issue
I've been having. Our software makes ample use of inheritance in all kinds
of manners but one thing struck me as odd.
There's an abstract base class (let's call it CEdsDocument, since it is its
name) that defines a few common functions and some abstract ones:
class CEdsDocument abstract : public CDocument
{
public:
CEdsDocument();
virtual ~CEdsDocument();
[cut for brevity et al.]
virtual afx_msg void OnStopExec() abstract;
}
CEdsDocument::~CEdsDocument()
{
OnStopExec();
[Bunch of other stuff]
}
The compiler (VC++ 9) accepts it but the linker won't since there is no
CEdsDocument::OnStopExec(). But, whenever the destructor is called, the
function will exist since it's pure virtual.
Then I saw Herb Sutters article at http://www.gotw.ca/gotw/031.htm and it
got me thinking. Providing a body for OnStopExec() doesn't help since the
abstract base class' version of the function gets called.
Is there a way to call a pure virtual function from the destructor of the
abstract class that declared it? Or is it Just Plain WrongT?
I've been having. Our software makes ample use of inheritance in all kinds
of manners but one thing struck me as odd.
There's an abstract base class (let's call it CEdsDocument, since it is its
name) that defines a few common functions and some abstract ones:
class CEdsDocument abstract : public CDocument
{
public:
CEdsDocument();
virtual ~CEdsDocument();
[cut for brevity et al.]
virtual afx_msg void OnStopExec() abstract;
}
CEdsDocument::~CEdsDocument()
{
OnStopExec();
[Bunch of other stuff]
}
The compiler (VC++ 9) accepts it but the linker won't since there is no
CEdsDocument::OnStopExec(). But, whenever the destructor is called, the
function will exist since it's pure virtual.
Then I saw Herb Sutters article at http://www.gotw.ca/gotw/031.htm and it
got me thinking. Providing a body for OnStopExec() doesn't help since the
abstract base class' version of the function gets called.
Is there a way to call a pure virtual function from the destructor of the
abstract class that declared it? Or is it Just Plain WrongT?