【问题标题】:namespace over a #include header file question#include 头文件问题上的命名空间
【发布时间】:2011-07-25 19:22:48
【问题描述】:

我将代码从 Windows 机器移植到 Mac。我正在使用带有 Xcode 3.2.5 的 OS X 10.6

我有一个名为 api.h 的头文件,其中包含以下代码:

namespace ocip {
    #include "onan/ocip/ocip.h"
}

ocip.h 包括#include stdint.h
其中有以下 typedef:

 typedef unsigned int         uint32_t;

现在回到 api.h 我有以下课程:

ocip::uint32_t m_nMode;

编译器告诉我命名空间 'ocip' 中的 uint32_t 没有命名类型。

任何想法我做错了什么?

【问题讨论】:

    标签: xcode namespaces stdint


    【解决方案1】:

    我不知道这是否会有所帮助,但可能已经声明了“uint32_t”类型。如果您包含“stdint”,则已经存在同名的 typedef。这可能会导致在 opic.h 中重新定义它时出现问题。

    【讨论】:

    • 我刚刚意识到我在我的问题中遗漏了那个关键词,ocip.h 包括 stdint.h,我希望 ocip::uint32_t 会是。这是否意味着如果我包含 stdint.h 我不能像我在问题中尝试的那样使用它周围的命名空间?
    • stdint 中的所有内容都在 std 命名空间中。尝试“ocip::std::uint32_t”,但我认为您可能必须将#include 移到命名空间声明之外(在它之前),然后执行“使用命名空间 std”
    • 似乎 uint32_t 不在 std 命名空间中,因为 std::uint32_t 在前面有或没有 ocip:: 或包含 using namespace std; 时都不起作用。当我查看 stdint.h 时,它也没有命名空间。 ocip::uint32_t 似乎仍然可以工作,但它没有
    • 你是对的。你有轻微的拼写错误吗?我知道这听起来很愚蠢,但是:daniweb.com/software-development/cpp/threads/215315
    • 这实际上可能会有所帮助:stackoverflow.com/questions/1204118/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    相关资源
    最近更新 更多