How to create Constructor in CPP
#include
using namespace std;
//create class
class Student{
public: // A.s
int id; //D.M
string nm; // D.M
//member function
void insert(int i, string n){
id=i;
nm=n;
}
void disp(){
cout<<"ID:"<
// Default Constructor Example
#include
using namespace std;
//create class
class Student{
public: // A.s
int id; //D.M
string nm; // D.M
//member function
void insert(){
cout<<"Enter ID & Name: ";
cin>>id>>nm;
}
void disp(){
cout<<"ID:"<
// Parametrized Constructor Example
#include
using namespace std;
//create class
class Student{
public:
int id;
string nm;
Student(int i, string n){
id=i;
nm=n;
}
void disp(){
cout<<"ID"<
agyanadda
Author & Editor
Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.
This comment has been removed by a blog administrator.
ReplyDelete