a =20;
class X {
private:
int data;
public:
~X()
{
cout << "Destruktor " << data << '\n';
}
X(int d = -1) : data(d)
{
cout << "Allgemeiner Konstruktor " << data << '\n';
}
X(const X &x) : data(x.data)
{
cout << "Kopierkonstruktor " << data << '\n';
}
X& operator=(const X& x) //nimmt auch Konstanten (wie in etwa 20)
{
data = x.data;
cout << "Zuweisungsoperator " << data << '\n';
return *this;
}
void set(int d)
{
data = d;
}
int get()
{
return data;
}
};
X a(0);
int main()
{
cout << '\n' << "Start main" << '\n';
X a; // Allgemeiner Konstruktor -1
a =20;
// Allgemeiner Konstruktor 20
// Zuweisungsoperator 20
// Destruktor 20
char g;
cin >> g;
return 0;
}
basicly a = 20 should be an assignment by using the assignment operator.
But it also works without the assignment operator.
It would just print out:
Allgemeiner Konstruktor 20
Destruktor 20
instead.
So what happens here ? can't the compiler decide wether ist is an assignment or a constructor call ?
why is this ?
and why is there an destructor call ? it's definetely not because it reaches the end of the programm..because it still awaits "cin >> f"




















