C++ 冲突声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11890083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Conflicting declaration
提问by user1496542
I have a typedef defined in my code as
我在我的代码中定义了一个 typedef
typdef unsigned int size_t;
it is conflicting with stddef's
它与 stddef 相冲突
typedef __SIZE_TYPE__ size_t;
I'm unsure how to get around this but would still like to keep size_t in my code.
我不确定如何解决这个问题,但仍想在我的代码中保留 size_t。
回答by Luchian Grigore
TwoThree options:
二三个选项:
1) Pick a different name, I think you already got that.
1)选择一个不同的名字,我想你已经知道了。
2) Use a namespace
:
2)使用namespace
:
namespace X
{
typedef long size_t;
}
and the type as
和类型为
X::size_t x;
3) Ugly, guaranteed to get you fired, and me downvoted:
3)丑陋,保证让你被解雇,我投反对票:
typedef unsigned int my_size_t;
#define size_t my_size_t
回答by jwismar
It is probably a bad idea to try to redefine a type that's in one of the standard headers. What are you trying to accomplish? Why don't you want to use the standard size_t definition?
尝试重新定义标准头文件之一中的类型可能是一个坏主意。你想达到什么目的?为什么不想使用标准的 size_t 定义?