Featured Post
- Get link
- X
- Other Apps
What is Constructer in C++ ?
Ans: Constructer is a special member function of Class object .A constructor in C++ is a special method that is automatically called when an object of a class is created. when we define a class in c++ than class name is same constructer name like when class name is demo than constructer define in class as demo(){}.
Example:-
#include <iostream>
using namespace std;
class demo {
public:
demo() {
cout << "Hello World!";
}
};
int main() {
demo myObj;
return 0;
}
What is Distructor ?
Ans:- Distructor perform in C++ like Constructer but it is opposite of Constructer.
Distructor define with (~) tield sign before constructer.
Example:-
#include <iostream>
using namespace std;
class demo {
public:
demo() {
cout << "Hello World!";
}
~demo(){
cout<<"Distructor";
};
int main() {
demo obj;
demo obj;
return 0;
}
Comments
Post a Comment
do not enter any spam link