Why C++ doesn't allow this?
Code:
#include <iostream.h>
#include <stdlib.h>
class fourpoint
{
public:
int w,x,y,z;
fourpoint();
fourpoint(int w,int x,int y,int z);
~fourpoint();
} ;
fourpoint::fourpoint()
{
}
fourpoint::fourpoint(int w=0,int x=0,int y=0,int z=0)
{
this->w=w;
this->x=x;
this->y=y;
this->z=z;
}
fourpoint::~fourpoint()
{
}
int main()
{
fourpoint *sh= new fourpoint(40,40);
cout<<endl<< sh->w <<" "<< sh->x;
cout<< " "<< sh->y <<" "<< sh->z<<endl<<endl;
system("PAUSE");
return 0;
}
I can't do this
fourpoint *sh= new fourpoint( , ,40,40);//error
Looks like not very flexible to me as it allows no parameters for the back but it needs you to put parameters in front even though the value of front parameters is default.
p.s. the above program doesn't do anything useful, it was written by me to test whether no front parameters works or not.