program in which each destructor should display different message e.g. for object 1 the message should be like this: “Object 1 is going to destroy”
#include <iostream>
#include <string>
class ExampleFirst
{
public:
void setDataset(std::string name, int value)
{
m_name = name;
m_value = value;
}
void viewDataset() {
std::cout << "name: " << m_name << std::endl;
std::cout << "value: " << m_value << std::endl;
}
~ExampleFirst()
{
std::cout << "object of class ExampleFirst will be destroyed" << std::endl;
}
private:
std::string m_name;
int m_value{0};
};
class ExampleSecond
{
public:
void setDataset(std::string name, int value)
{
m_name = name;
m_value = value;
}
void viewDataset() {
std::cout << "name: " << m_name << std::endl;
std::cout << "value: " << m_value << std::endl;
}
ExampleSecond(std::string n, int v)
{
m_name = n;
m_value = v;
}
~ExampleSecond()
{
std::cout << "object of class ExampleSecond with slanderous data " << std::endl;
viewDataset();
std::cout << "will be destroyed" << std::endl;
}
private:
std::string m_name;
int m_value{ 0 };
};
int main()
{
// example test
ExampleFirst first;
first.setDataset("test1", 1);
ExampleSecond second("test2", 2);
return 0;
}
Comments
Leave a comment