Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does C++ offer mated constructor / destructor combos?

19 views
Skip to first unread message

Rick C. Hodgin

unread,
Jul 10, 2018, 1:33:57 PM7/10/18
to
Is there something like this:

class CWhatever
{
public:
// Mated constructor / destructor pair
CWhatever(... params ...)
{
// Constructor code here
std::cout << "Constructor" << std::endl;

} ~ {
// Mated destructor code here
std::cout << "Mated destructor" << std::endl;
}

// Generic destructor
~CWhatever()
{
// Generic destructor code here
std::cout << "Generic destructor" << std::endl;
}

// Other things here
};

Such that it would generate this output on use:

Constructor
Mated destructor
Generic destructor

--
Rick C. Hodgin

Ian Collins

unread,
Jul 10, 2018, 4:22:14 PM7/10/18
to
No.

There is only ever one destructor. If the work of the destructor
depends on how the object was construct, include a flag. This pattern
is uncommon.

--
Ian.
0 new messages