由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Question about name resolution in C++
相关主题
guess what is this code for?还请教一个关于C++的问题
Nested classes inside one class (C++)最初级的白痴C++问题
a simple question for C++ class数组定义的时候,分配空间了么?
关于 VC++ vitual, reload 和 derive的一个问题...C++: 下面代码有啥问题,为什么?
ask a C++ inheritance questionC++疑问
三个C syntax 弱问题请教一个作用域的问题
发个初级面试题请教一个C++的编程
C++ interview questions help[合集] C++问题(copy constructor)
相关话题的讨论汇总
话题: foo话题: c++话题: question话题: name话题: class
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] C++问题(copy constructor)ask a C++ inheritance question
C++ Singleton Help三个C syntax 弱问题
C++编译的问题发个初级面试题
Why should i include .cpp instead of .hC++ interview questions help
guess what is this code for?还请教一个关于C++的问题
Nested classes inside one class (C++)最初级的白痴C++问题
a simple question for C++ class数组定义的时候,分配空间了么?
关于 VC++ vitual, reload 和 derive的一个问题...C++: 下面代码有啥问题,为什么?
相关话题的讨论汇总
话题: foo话题: c++话题: question话题: name话题: class