关于定义不完整的问题 [英] A question on incomplete definitions

查看:92
本文介绍了关于定义不完整的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello group,

你能帮我解决这个问题:


static const int x;

.... ........东西.............

静态const int x = 17;


它对我来说看起来完全合法,但MSVC / C ++ 6.0在第一行给出了

"警告C4132:''x'':const对象应该初始化

然后生成正确的代码。


什么是正确的 - 代码或编译器?如果代码,是否知道什么

编译器对此扼杀了多少?


谢谢,

方舟

Hello group,
Could you help me with this:

static const int x;
............ something .............
static const int x = 17;

It looks perfectly legal to me but MSVC/C++ 6.0 gives, on the first line,
"warning C4132: ''x'' : const object should be initialized"
yet generates correct code.

What is correct - the code or the compiler? If the code, is it known what
compilers choke on this and how hard?

Thanks,
Ark

推荐答案



" ark" < AR **** @ comcast.net>在消息中写道

"ark" <ar****@comcast.net> wrote in message
static const int x;

这是x的暂定前向声明。
............ ............
静态const int x = 17;

这是x的声明
它看起来完全合法,但MSVC / C ++ 6.0在第一行
上给出了警告C4132:''x'':const对象应该初始化
然后生成正确的代码。

什么是正确的 - 代码还是编译器?如果是代码,是否知道
编译器会对此产生什么影响以及有多难?
static const int x;
This is a tentative forward declaration of x.
........... something .............
static const int x = 17;
This is the declaration of x
It looks perfectly legal to me but MSVC/C++ 6.0 gives, on the first
line, "warning C4132: ''x'' : const object should be initialized"
yet generates correct code.

What is correct - the code or the compiler? If the code, is it known
what compilers choke on this and how hard?



允许编译器对代码进行警告,这些代码是正确但看起来很好看

可疑。在这里你使用了一个常用的const结构,所以它b / b
你是否知道自己在做什么。


我也会发出警告因为我怀疑你在代码中的所有静态const整数都不需要暂定的

前向声明。但是我可能是错误的。


The compiler is allowed to give warnings for code which is correct but looks
suspicious. Here you are using a little-used construct with a const, so it
wonders if you know what you are doing.

I would also give a warning, since I suspect that you don''t need a tentative
forward declaration at all of a static const integer in your code. However I
may be wrong.


ark< ar **** @ comcast.net>写道:
ark <ar****@comcast.net> wrote:
Hello group,
你能帮助我吗:
static const int x;


你声明并定义x,隐含值为0.

但是,由于对象是const,你没有机会

来改变它的价值。 AFAIK,这个结构是有效的,但是

基本上没有意义。

............ .......... ......
static const int x = 17;


您重新定义并重新定义x值为17.这个

显然是不正确的,因为x标识符已经存在

存在且有存储。

它看起来完全合法,但MSVC / C ++ 6.0在第一行上给出了警告C4132:''x'':const对象应该被初始化
然后生成正确的代码。
Hello group,
Could you help me with this: static const int x;
You declare and define x, with the implicit value of 0.
However, since the object is const, you won''t have a chance
to change its value. AFAIK, this construct is valid, but
is largely meaningless.
........... something .............
static const int x = 17;
You redeclare and redefine x with the value of 17. This
is obviously incorrect because the x identifier already
exists and has storage.
It looks perfectly legal to me but MSVC/C++ 6.0 gives, on the first line,
"warning C4132: ''x'' : const object should be initialized"
yet generates correct code.




这是一个友好的警告,说你的第一行

并没有多少感。这可能不是必需的

诊断。


Alex



This is a friendly warning that says that your first line
doesn''t make much sense. It is probably not a required
diagnostic.

Alex




" Malcolm" <毫安***** @ 55bank.freeserve.co.uk>在消息中写道

news:br ********** @ newsg1.svr.pol.co.uk ...

"Malcolm" <ma*****@55bank.freeserve.co.uk> wrote in message
news:br**********@newsg1.svr.pol.co.uk...

< ;剪断>我也会发出警告,因为我怀疑你不需要代码中所有静态const整数的
暂定前向声明。但是
我可能错了。
<snip> I would also give a warning, since I suspect that you don''t need a tentative forward declaration at all of a static const integer in your code. However I may be wrong.




想象一下,例如,一个头文件#define'对x很有用(这是

很可能是某种形式的结构)。然后标题需要一个

暂定前向声明。 x,这里有用恕我直言。

对于错误的术语很抱歉,

- 方舟



Imagine, e.g., a header file that #define''s useful thing about x (which is
really likely to be a struct of some sort). Then the header needs a
"tentative forward declaration" of x, and here it is useful IMHO.
Sorry for wrong terminology,
- Ark


这篇关于关于定义不完整的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆