Here you output a and b which are not initialized:
A(){
cout<<a<<" "<<b;
}
And here you initialize a and b, but you create an anonlymous temporary object
A(int x , int y){
a = x; b= y;
A(); // !!!! CREATES AT TEMPORARY ANONYMOUS OBJECT WITH IT'S OWN a and B
}
To use a delegated constructor (i.e. using another constructor to finish the construction process of the SAME object) you have to use the delegeted constructor in the initialisation list :
A(int x , int y) : A() { a=x; b=y; }
Unfortunately, when you use delegation, the delegate must be the ONLY meminitializer in the list. This requires that the initialisation of a and b would happen after A().
Another alternative:
class A
{
public:
int a, b;
A() : A(0, 0) { } // use a delegated ctor
A(int x, int y) : a(x), b(y) { cout << a << " " << b; }
};
Still another alternative, using defaults (without reusing a constructor) :
class A
{
public:
int a, b;
A(int x=0, int y=0) : a(x), b(y) { cout << a << " " << b; }
};