VS2010 中的名称查找错误

发布于 2024-10-06 10:01:17 字数 378 浏览 0 评论 0原文

我很确定这是 VS 2010 中的一个错误,但检查 SO

struct A{
   static int s;
}; 

struct B{ 
   static int s;
}; 

struct C : A, B{ 
   void fn(short s){ // Ambiguous access of 's' here!!!
      s = 2;               
   } 
}; 

int A::s;
int B::s;

int main(){ 
   C c;
}

VS 给出的错误总是一个好主意 - “错误 C2385:'s' 的访问不明确”。

g++ 和 Comeau 编译良好。

我错过了什么吗?

I am pretty sure it is a bug in VS 2010, but it's always a good idea to check on SO

struct A{
   static int s;
}; 

struct B{ 
   static int s;
}; 

struct C : A, B{ 
   void fn(short s){ // Ambiguous access of 's' here!!!
      s = 2;               
   } 
}; 

int A::s;
int B::s;

int main(){ 
   C c;
}

VS gives- "error C2385: ambiguous access of 's'".

g++ and Comeau compile fine.

Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眸中客 2024-10-13 10:01:17

Visual C++担心菱形问题——名为“s”的实例成员由于菱形继承而具有二义性。但在这里,它应该被名为“s”的本地参数遮蔽,因此这段代码没有任何非法之处。它应该干净地编译,除非您在环境中设置了一些奇怪的东西以使 Visual C++ 抱怨隐藏的变量名称。

Visual C++ is worried about the diamond problem- the instance member named "s" is ambiguous due to diamond-shaped inheritance. But here, it should be shadowed by the local parameter named "s", so there's nothing illegal about this code. It should compile cleanly, unless you have something weird set in your environment to make Visual C++ complain about shadowed variable names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文