【问题标题】:VS2013 is having trouble with base class being in unnamed namespaceVS2013 遇到基类在未命名命名空间中的问题
【发布时间】:2015-01-07 02:53:56
【问题描述】:

以下代码可以正常编译并按预期运行:

#include <iostream>

namespace
{
    struct Base
    {
        void print() const { std::cout << "test"; };
    };
};

class Derived : public Base
{
};

int main()
{
    Derived d;
    d.print();
    return 0;
}

但是在运行时使用 QuickWatch 查看 d 时,IntelliSense 似乎无法找到 基地。

我通过将 Base 放在命名空间而不是未命名的命名空间中解决了这个问题。

这是 Visual Studio 中的错误,还是我遗漏了什么?

【问题讨论】:

    标签: c++ debugging visual-c++ visual-studio-2013


    【解决方案1】:

    这个匿名命名空间问题在 VC++ 中已经存在一段时间了 - 请参阅 http://msdn.microsoft.com/en-us/library/0888kc6a%28VS.80%29.aspx。来自链接的文档:

    本机 C++ 表达式求值器不支持匿名命名空间。

    在这个例子中观察符号测试的唯一方法是使用修饰名:

    例如(int*)?test@?A0xccd06570@mars@@3HA(使用示例中给出的命名空间层次结构来说明这一点)。只使用装饰名称?这太方便了!谢谢,微软。

    【讨论】:

    • @Drop:它让你想知道“标准”的内部词是什么。
    猜你喜欢
    • 1970-01-01
    • 2015-03-04
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    相关资源
    最近更新 更多