【发布时间】:2012-10-29 21:27:39
【问题描述】:
在 C++11 中,我可以选择是否要使用定义的类型,带或不带命名空间 std::
至少我的编译器 (g++ 4.7) 接受这两种变体。
我的问题是:使用 cstdint 中的 typedef 的推荐方法是什么。有或没有命名空间?有什么优点或缺点?还是只是风格问题?
所以变体a):
#include <cstdint>
std::uint8_t n = 21;
回复:
#include <cstdint>
using std::uint8_t;
uint8_t n = 21;
或变体 b):
#include <cstdint>
uint8_t n = 21;
【问题讨论】:
-
我认为 C++11 删除了对
std中的 C 内容的重构。 -
我认为您在第一个示例中的意思是“std::”,而不是“std:”
-
@u8sand:没错。谢谢!我更正了。
-
我会使用
#include <stdint.h> uint8_t n = 21;。