views:

74

answers:

1

If the answer is yes, can you tell me why? here is an example:

namespace urx {
    struct reserved { };
    struct side { urx::reserved reserved() { /*...*/ } };
}

int main() {
    urx::side side;
    side.reserved();
}

reserved is used for both a type name and a function name. side is used for both a type name and a variable name. but in both cases, they are separated by urx namespace and i always explicitly specify urx for referring to a type name (for readability).

+2  A: 

I don't see why this would be bad. I think I would rather name my member functions consistently with good names than to invent hard to remember artificial names to disambiguate them.

Some coding guidelines are written such that this case cannot happen. By forcing types to start with an upper-case letter and functions with a lower-case letter and such.

You should avoid calling your member functions according to common template names though. The following program is ill-formed according to current C++ Standard, though some compilers tend (for the good) to ignore that error. Clang and comeau give a warning

#include <vector>
using namespace std;

struct A {
  template<typename T>
  T vector();
};

int main() {
  A a;
  a.vector<int>(); // ill-formed!
}
"ComeauTest.c", line 11: warning: ambiguous class member reference -- function  
          template "A::vector" (declared at line 6) used in preference to  
          class template "std::vector" (declared at line 163 of  
          "stl_vector.h")
  a.vector(); // ill-formed!
    ^

It has been proposed to get rid of this.

Johannes Schaub - litb
I think g++ accepts the code without giving any warning. I read a post of yours where you had posted a similar example. Can't find that thread.
Prasoon Saurav
Thanks, i got my answer :) then i should go with that practice.
PC2st