+ 5

Please give syntax to creat a constructor and destructor inside a class

7th Jul 2017, 12:27 PM
KABILESH KANNAN
KABILESH KANNAN - avatar
6 Answers
+ 1
ClassName () { /* constructor */ } ~ClassName () { /* destructor */ }
7th Jul 2017, 12:48 PM
soman
+ 1
public abc { abc(); //constructor }
7th Jan 2018, 2:56 PM
Arif Ramjan Sanadi
Arif Ramjan Sanadi - avatar
+ 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.
7th Jul 2018, 5:43 AM
Sanjit Paul
Sanjit Paul - avatar
+ 1
use class name as it is in public section of your main class.
22nd Jul 2018, 12:50 PM
Arif Ramjan Sanadi
Arif Ramjan Sanadi - avatar
0
learn it.. it is provided in the course
7th Jul 2017, 12:39 PM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
0
#include "MyClass.h" #include <iostream> using namespace std; MyClass::MyClass() { cout<<"Constructor"<<endl; } MyClass::~MyClass() { cout<<"Destructor"<<endl; }
7th Jan 2018, 2:57 PM
Arif Ramjan Sanadi
Arif Ramjan Sanadi - avatar