I want to create a member function with the same name of the returning type. Example:
class A { };
class B {
public:
A& A() { return *a; }
private:
A* a;
};
However, the compiler won’t let me. I tried to change the type of the member return type to ::A (as sugested here, but with no avail. I know I could just change the member name, but I just want to understand why does it has this restriction, and what are my workarounds.
If you declare a member called
Ayou can no longer use the typeAwithout an explicit namespace. You need to change every occurrence of the type A to::A.The corrected code looks like:
Fixed code on codepad:
http://codepad.org/cilF9rKm