d****p 发帖数: 685 | 1 Recently one of my colleagues did something below:
A.h
class A
{
public:
...static void Foo() { ... }
};
B.cpp
#include "A.h"
namespace MyStuff {
void A()
{
....A::Foo(); // name clash for function A and class A
}
}
The funny thing is visual studio c++ accepts this so he checked the above
code in and thus broke unix build.
He finally fixed this by using another name for function A in B.cpp.
My question is: is there a way to get the thing around without changing
names for either class A or functi |
t****t 发帖数: 6806 | 2 but i think this IS valid.
【在 d****p 的大作中提到】 : Recently one of my colleagues did something below: : A.h : class A : { : public: : ...static void Foo() { ... } : }; : B.cpp : #include "A.h" : namespace MyStuff {
|
d****p 发帖数: 685 | 3 So it is allowed by standard? Could be since one A is class and the other is
function.
However, g++ 3.3 on redhat, g++ 4.2 on OSX, solaris CC 5.6, XLC on AIX all
reject the code above.
【在 t****t 的大作中提到】 : but i think this IS valid.
|
d****p 发帖数: 685 | 4 I guessed the right way is to qualify class A when calling its static member
function Foo, like |
t****t 发帖数: 6806 | 5 yes, i tried your original post on gcc-4.4 and it passed.
gcc-4.1 rejected it, but accepts ::A::Foo().
member function Foo, like ::A::Foo()
【在 d****p 的大作中提到】 : I guessed the right way is to qualify class A when calling its static member : function Foo, like
|