为什么在构建结构时在Visual C ++ 2008中收到这些警告? [英] Why do I get these warnings in Visual C++ 2008 when building a struct?

查看:263
本文介绍了为什么在构建结构时在Visual C ++ 2008中收到这些警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码

  typedef struct 
{
const char * fooString;
const bool fooBool;
} fooStruct;

此初始值程式:

  static const fooStruct foo [] = 
{
{file1,true},
{file2,false},
... 。
};

使用这个代码我在VS2008有3个警告:

 错误C2220:警告被视为错误 - 无对象文件生成
警告C4510:'< unnamed-tag>':无法生成默认构造函数
警告C4512:'<未命名标签>':不能生成赋值运算符
警告C4610:struct'< unnamed-tag>'永远不能实例化 - 用户定义构造函数


解决方案

C4610警告不正确。这是Visual C ++中的一个已知错误。请参阅Microsoft Connect错误C4610的不当发布。

Adam Rosenfield说明为什么发出其他两个警告(C4510和C4512)。


I have this code

typedef struct
{
    const char* fooString;
    const bool  fooBool;
}fooStruct;

And this initializer:

static const fooStruct foo[] =
{
    {"file1", true},
    {"file2", false},
    ....
};

With this code I have 3 warnings in VS2008:

error C2220: warning treated as error - no 'object' file generated  
warning C4510: '<unnamed-tag>' : default constructor could not be generated
warning C4512: '<unnamed-tag>' : assignment operator could not be generated
warning C4610: struct '<unnamed-tag>' can never be instantiated - user defined constructor required 

解决方案

The C4610 warning is incorrect. This is a known bug in Visual C++. See the Microsoft Connect bug "Improper issuance of C4610."

Adam Rosenfield explains why the other two warnings (C4510 and C4512) are emitted.

这篇关于为什么在构建结构时在Visual C ++ 2008中收到这些警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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