Tuesday 20 April 2021

Constructor in C++ - 2

 #include<iostream.h>

#include<conio.h>

class A

{

public:

int a , b;

A(int a,int b)

{

this->a=a;

this->b=b;

cout<<this->a+this->b<<endl;    //14

}

};

int main()

{

clrscr();

A ob=A(6,8);

cout<<ob.a+ob.b<<endl;  //garbage

getch();

return 0;

}

No comments:

Post a Comment