【问题标题】:forward declaration of namespace命名空间的前向声明
【发布时间】:2012-12-15 11:12:25
【问题描述】:
namespace CounterNameSpace {
    int upperbound;
    int lowerbound;
    using namespace NS;//Error
}
namespace NS {
int i;
}
// ...
namespace NS {
int j;
}

在上述情况下,它显示一个错误。 错误 C2871:“NS”:具有此名称的命名空间不存在 我知道如果我在 counternamespace 问题得到解决之前定义 NS 。但是只想知道c++中是否存在诸如命名空间的前向声明之类的东西。这样就可以解决上述问题而无需在counternamespace之前定义NS。 请帮忙。

【问题讨论】:

  • @user1872084::以上链接与类的前向声明有关。

标签: c++ namespaces forward-declaration


【解决方案1】:

没有什么说命名空间需要它的所有内容:

namespace NS {}
namespace CounterNameSpace {
    int upperbound;
    int lowerbound;
    using namespace NS;
}
namespace NS {
int i;
}

但是,这可能无法满足您的要求。在您声明它们之前,您仍然无法使用该命名空间中的任何类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-20
    • 2012-12-27
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多