1) First Code
class A
{
public:
int i;
int b;
A(int temp){
i=temp;
A();
b=0;
}
A(){
b=0;
}
void display(){
printf("%d %d\n",i,b);//1 0
}
};
int main(){
A Aobj(1);
Aobj.display();
return 0;
}
Output: 1 0
2) Second Code
class A
{
public:
int i;
int b;
A(int temp) : i(temp), A(), b(0) {}//Error
A() : b(0) {}
void display(){
printf("%d %d\n",b,i);
}
};
int main()
{
A Aobj(1);
Aobj.display();
return 0;
}
I was expecting that both the codes will show same behavior and will produce an error as calling one constructor from the other in the same class is not permitted. It's not C++11.
So why does using the intializer list make a difference? I compiled this codes in g++ 4.3.4 .