Menu

Custom Search

C++ lab Program

/*modify above problem by passing default value to both the arguments in the parametrised constructor and try to create an object without passing any arguments.explain out come.*/
#include
#include
class test
{
int x,y;
public:
test()
{ x=0;
y=0;
cout<<"Default constructor:"<
}
test(int a=5,int b=5)
{ x=a;
y=b;
cout<<"Parameterized constructor:"<
}
void show();
};
void main()
{
clrscr();
test t1;
test t2; //error message 'test::test()' and 'test::test(int,int)'
//structure required on left side of .or.*
t1.show();
t2.show();
getch();
}

void test::show()
{
cout<<"X="< cout<<"Y="< cout<<"X*Y="< }

/*
message:
ambiguity between 'test::test()' & 'test::test(int,int)'*/

No comments:

Post a Comment