c++compiler-constructionnaming-conventionsmethod-names

G++ compiler cannot distinguish variable and function with the same name?


Possible Duplicate:
Class method and variable with same name, compile error in C++ not in Java?

The G++ compiler would complain when my class member name and member function name are the same. It seems that whenever a variable name happens to be the same as a function name, the compiler would complain.

In Java, it is not the case. I just wonder why the G++ compiler cannot distinguish a variable name from a function name since the function name always comes with a pair of parenthesis.


Solution

  • struct Callable
    {
        void operator()() const { }
    };
    
    struct Test
    {
        void Call() { }
        Callable Call;
    };
    
    int main()
    {
        Test x;
        x.Call(); // To which 'Call' does this refer?
    }