warning 4510 with const member in struct
I write a code section as this
struct My
{
const int a;
};
OK, then set the warning level

then I will got this
c:\users\luli1\documents\visual studio 2013\projects\consoleapplication3\header1.h(4): error C2220: warning treated as error - no 'object' file generated
1>c:\users\luli1\documents\visual studio 2013\projects\consoleapplication3\header1.h(4): warning C4510: 'My' : default constructor could not be generated
1> c:\users\luli1\documents\visual studio 2013\projects\consoleapplication3\header1.h(2) : see declaration of 'My'
1>c:\users\luli1\documents\visual studio 2013\projects\consoleapplication3\header1.h(4): warning C4512: 'My' : assignment operator could not be generated
1> c:\users\luli1\documents\visual studio 2013\projects\consoleapplication3\header1.h(2) : see declaration of 'My'
1>c:\users\luli1\documents\visual studio 2013\projects\consoleapplication3\header1.h(4): warning C4610: struct 'My' can never be instantiated - user defined constructor required
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The ways to stop this are list below
1.
struct My
{
const int a;
My (int i):a(i){}
};
2.in the property->c++->advanced, set "disable specific warning" as 4510, there you go
3. in the .h file , put on the top
#pragma warning (disable:4510), and note that if you have inlcude an .h file that has this definition is also OK
Actually, replacing the struct with class, it may be easier to understand.
You may encounter with the warning 4512, but it is another story... :)
warning 4510 with const member in struct的更多相关文章
- C++ 之const Member Functions
Extraction from C++ primer 5th Edition 7.1.2 The purpose of the const that follows the parameter lis ...
- [C++] static member variable and static const member variable
static member variable[可读可写] 可以通过指针间接修改变量的值 static const member variable[只读] 压根就不可以修改变量的值,会报错
- C++ Data Member内存布局
如果一个类只定义了类名,没定义任何方法和字段,如class A{};那么class A的每个实例占用1个字节的内存,编译器会会在这个其实例中安插一个char,以保证每个A实例在内存中有唯一的地址,如A ...
- C++ c++与C语言的区别(三目运算符,const修饰符)
//区别⑦:三目运算符(C++版本) #include<iostream> using namespace std; //三目运算符 C语言返回变量的值 C++语言是返回变量本身 void ...
- C++11 关键字 const 到底怎么用?
Const 的作用及历史 const (computer programming) - Wikipedia 一.历史 按理来说,要想了解一件事物提出的原因,最好的办法就是去寻找当时的历史背景,以及围绕 ...
- C指针-const char* p到底是什么不可以改变
char a = 'w'; char b = 'q'; const char* p = &a; p = &b; printf("%c",p[0]); 如上一段代码, ...
- struct内存对齐1:gcc与VC的差别
struct内存对齐:gcc与VC的差别 内存对齐是编译器为了便于CPU快速访问而采用的一项技术,对于不同的编译器有不同的处理方法. Win32平台下的微软VC编译器在默认情况下采用如下的对齐规则: ...
- const成员函数
尽管函数名和参数列表都相同,void foo( ) const成员函数是可以与void foo( )并存的,可以形成重载! 我们假设调用语句为obj.foo(),如果obj为non-const对象,则 ...
- c++ const总结
[本文链接] http://www.cnblogs.com/hellogiser/p/cplusplus-const-summay.html 看到const 关键字,C++程序员首先想到的可能是con ...
随机推荐
- Tomcat Shell脚本(启动|关闭|重启|状态)
#!/bin/bash # # chkconfig: - # description: Tomcat start/stop/status script #Location of JAVA_HOME ( ...
- Vsftp精解之安装配置及原理(一)
简介 Vsftp(Very Secure FTP)是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,是一款小巧而又易用FTP服务器程序,Vsftpd 在安全性.高性能及稳定性三个方面有很好 ...
- python中if __name__ == '__main__': 的解析
当你打开一个.py文件时,经常会在代码的最下面看到if __name__ == '__main__':,现在就来介 绍一下它的作用. 模块是对象,并且所有的模块都有一个内置属性 __name__.一 ...
- 一步一步搭框架(asp.netmvc+easyui+sqlserver)-03
一步一步搭框架(asp.netmvc+easyui+sqlserver)-03 我们期望简洁的后台代码,如下: using System; using System.Collections.Gener ...
- VS属性页的目录类型
常用的三个: 1.可执行目录 :在其中搜索可执行文件的目录. 对应于 PATH 环境变量,即为.dll的目录. 2.包含目录 :在其中搜索源代码中所引用的包含文件的目录. 对应于 INCLUDE ...
- 【转】C#多线程学习
C#多线程学习(一) 多线程的相关概念 什么是进程?当一个程序开始运行时,它就是一个进程,进程包括运行中的程序和程序所使用到的内存和系统资源.而一个进程又是由多个线程所组成的. 什么是线程?线程是程序 ...
- js版扫雷(可直接运行试玩)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C#队列
队列(Queue)是插入操作限定在表的尾部而其它操作限定在表的头部进行的线性表.把进行插入操作的表尾称为队尾(Rear),把进行其它操作的头部称为队头(Front).当对列中没有数据元素时称为空对列( ...
- sumoselect插件
由于项目需要,研究了下sumoselect插件,接下来简单介绍下sumoselect. 在百度上搜索“sumoselect.js”,查到的网页基本上都有对sumoselect的基本介绍,如下: 简单介 ...
- SlickUpload 发布到IIS后报错
开发时候采用slickupload控件都没问题,项目发布到IIS时发生了错误: Could not contact SlickUpload request progress handler at /S ...