Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it ok not to explicitly define destructor?

Status
Not open for further replies.

Lorey

Programmer
Feb 16, 2003
88
SG
class Class1: public MotherClass1
{
public:
Class1(const BufferType & buffer);

//<*** no destructor defined *** >

int getHead() const;

/**
*
*/
virtual std::eek:stream & streaming(std::eek:stream & os)

private:

int m_head;
class1(const class1 &)
class1 & operator=(const class1 &)


}
 
There are a few functions that the compiler generates for you if you don't explicitly define them:
Default Constructors, Copy Constructors, Copy Assignment Operators, and Destructors.
However, the default destructors that are generated aren't virtual, so if your class is a base class, you should define a virtual destructor to prevent slicing and other bad things like that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top