C++ Class Destructor Question

Introduction

Write a program that defines a class called MyClass with a user-defined default constructor and user-defined destructor.

Define both constructor and destructor outside the class.

Both member functions will output a free to choose the text on the standard output.

Create an object of a class in function main.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 

class MyClass 
{ 
public: 
    MyClass(); 
    ~MyClass(); 
}; 

MyClass::MyClass() 
{ 
    std::cout << "Constructor invoked." << '\n'; 
} 

MyClass::~MyClass() 
{ 
    std::cout << "Destructor invoked." << '\n'; 
} 

int main() 
{ 
    MyClass o; 
} 



PreviousNext

Related