C++:
#include <iostream>
using namespace std;
class X {
int a;
public:
X(int n = 6) : a {n} {}
X(const X& x) : a{x.a} {cout << "CP";}
friend ostream& operator<<(ostream&, X);
};
ostream& operator<<(ostream& o, X x) {
return o << x.a+4;
}
int main() {
X x {1};
cout << x;
return 0;
}//Danke fuer die zahlreichen Antworten und tipps!
//Eine Frage noch: werden in dem Fall beide Konstruktoren (also Defaultkonstruktor und der Kopierkonstruktor) aufgerufen, oder wie funktioniert das?
Zuletzt bearbeitet: