#include <iostream>
using namespace std;
class A {
public:
A();
friend A &operator+(A &, const int);
int getValue() const;
private:
int val;
};
A::A() { val = 0; }
int A::getValue() const { return val; }
A &operator+ (A &sa, const int a) {
sa.val += a;
return sa;
}
int main(void) {
A q, w;
w + 3; // 1
q = q + 2; // 2
w = w + q.getValue(); // 3
cout << q.getValue() << w.getValue();
return 0;
}
@hrendashtam23 checked here: https://ideone.com/BhCH3Z . Looks fine so far
2017 Dec 1, 6:25:16 PM
Isn't A:: needed in this line? A &operator+ (A &sa, const int a) {
2017 Nov 19, 7:32:57 AM
Login in to like
Login in to comment