1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream> class A { private: int x; public: A operator+(const A&) const; }; A A::operator+(const A& b) const { A a; a.x = x + b.x; return a; } int main() { using namespace std; A a; a.x = 3; A b; b.x = 3; A c = a + b; cout << c.x; }
1 2 3
In function 'int main()': Line 5: error: 'int A::x' is private compilation terminated due to -Wfatal-errors.