sorry about the code tags. And the missing code is from being lazy.
I get the get(), that is just a getter :-). Since the overload of '=' for a setter worked, I tried to make it work for the getter. But, I am a bit confused. How would you define the getter function as an 'operator=' overload?
Also, if I added an int member, then I can add another overload operator=(int) for the int setter , but can use the same function name get() to return the int?
operator= is the "assignment operator", i.e., it is a "setter", so it would be very bad form indeed to define it as a "getter". Think about it. It doesn't make any sense at all, since you would use it something like x = y, which calls operator= on the x object, passing the y object: x.operator=(y). But you wouldn't even be using the y object since you just want to return a member of x. It's insane!
As for your get() functions, you can't overload a function on it's return type. You can just give them separate names, getInt(), getPtr().
Alternatively you could possibly use conversion operators:
1 2 3 4 5 6 7 8 9 10 11 12
class foo {
public:
...
operatorvoid*() const { return m_p; }
operatorint() const { return m_i; }
...
};
...
foo f;
f = 42;
int n = f; // n is 42 because of operator int()