+ 5
Please give syntax to creat a constructor and destructor inside a class
6 Réponses
+ 1
ClassName () { /* constructor */ }
~ClassName () { /* destructor */ }
+ 1
public abc
{
abc(); //constructor
}
+ 1
classname()
{
public :
classname () // Constructor
{
}
~classname () // Destructor
{
}
};
Remember that constructor or destructor should have no return type.
And it should be declared under public access specifier.
+ 1
use class name as it is in public section of your main class.
0
learn it.. it is provided in the course
0
#include "MyClass.h"
#include <iostream>
using namespace std;
MyClass::MyClass()
{
cout<<"Constructor"<<endl;
}
MyClass::~MyClass()
{
cout<<"Destructor"<<endl;
}