As i understand we can initiate an object s of class sample through a statement,
sample s=10;
Compiler will treat the statement as sample s(10)
. if there is a one argument constructor with in the class sample , the statement would work but if there is no one argument constructor then compiler will flash an error.
I want to know. can we initiate an object of class sample through a statement,
sample s=10,20;
this is shown in the following example:
class sample {
private:
int a,b;
public:
sample(int i) {
a=i;
b=i;
}
sample(int i, int j) {
a=i;
b=j;
}
void display(){
cout<<a<<endl<<b;
}
};
void main(){
sample s = 10;
sample c = 10,20;
c.display();
}
Would the above program work?