Constructor In C++ - HelpMeOutAlways

Monday, October 8, 2018

Constructor In C++

The constructor in C++ is a special type of function which is used to initialize any value when an object is created, there is no need to call the function.
It doesn't return any value. it has the same name as the class name.
For example, any person wants to open an account in the bank, so according to the bank policy you have to put 500 Rupees to start or run your account.
So, whenever any user will open an account, the amount will automatically be initialized to the user account, as given below.


SOurce COde


#include<iostream>

#include<conio.h>
using namespace std;
class bank{
public:
int iniAmount;
bank(){
iniAmount=500;
cout<<"Intial balance of User is:"<<iniAmount<<endl;
}
};
int main(){
bank user1;
getche();
}

Output


No comments:

@way2themes