How to define and use the destructor in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

class Test {
public:
	Test();                  
	~Test(); // destructor
};

Test::Test()
{
	cout << "constructor" << endl;
}

Test::~Test() // destructor
{
	cout << "destructor" << endl;
}

int main()
{
	Test o;

	return 0;
}


/*
run:

constructor
destructor

*/

 



answered Mar 24, 2018 by avibootz

Related questions

1 answer 170 views
1 answer 255 views
1 answer 176 views
1 answer 136 views
136 views asked May 12, 2021 by avibootz
...