C++/default constructor
Expert: vijayan - 4/14/2010
Question#include<iostream>
using namespace std;
int a(int,int);
class p
{
public:
int i;
p()
{
cout<<"constructing!!";
}
~p(void)
{
cout<<"Destructing!....pppp..";
}
};
class w
{
public:
int y;
w(void)
{
cout<<"constructing!!";
}
~w(void)
{
cout<<"Destructing!....the WWW..";
}
};
int main()
{
p ob(p,p,w);
w ob1;
return 0;
}
is there any error?can we send in the declaration any number of object i.e ob(p,p,......)!why is this happening can you tell me?
Answer p ob(p,p,w);
Has more than one error.
To start with, p and w are classes (types), not objects (variables).
Even if we had written
p ob(34,"hello",4.3);
There is an error. The only constructor in class p does not take any arguments.
There is no constructor which can be invoked with three arguments.