Groups
Groups
Sign in
Groups
Groups
comp.lang.c++
Conversations
About
Send feedback
Help
Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Learn more
Does C++ offer mated constructor / destructor combos?
19 views
Skip to first unread message
Rick C. Hodgin
unread,
Jul 10, 2018, 1:33:57 PM
7/10/18
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 PM
7/10/18
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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