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 ...
随机推荐
- ruby环境的配置
安装 Ruby 解析器 一些Linux发行版本,MacOSX操作系统都自带Ruby解析器,但是我仍然建议自行下载ruby源代码编译安装.因为一方面可以自己定制ruby安装的路径,另一方面可以在编译过程 ...
- Dapper学习笔记(3)-增、删、改、查
一.建表 在数据库中建立如下三张表: CREATE TABLE [dbo].[T_User] ( , ) PRIMARY KEY NOT NULL, ) NOT NULL, ) NULL, ) NUL ...
- Mac上安装与更新Ruby,Rails运行环境
Mac安装后就安装Xcode是个好主意,它将帮你安装好Unix环境需要的开发包,也可以独立安装command_line_tools_for_xcode 1.安装RVM RVM:Ruby Version ...
- python 笔记2:python语法基础
python语法学习笔记: 1 输入输出 input(),print(). name = input('input your name : ')print('hello ,'+name)print(& ...
- PCB设计规则考量之初识
PCB的设计规则可以分布局与走线.布局里最简单的原则就是避免信号之间的干扰,有把模拟部分与数字部分分开,把开关电源与数字部分分开,把端去耦电容靠近端点,而且从端点出来的电容容值按从小到大摆放效果会好些 ...
- [Python]命令行进度条
关键点是输出'\r'这个字符可以使光标回到一行的开头,这时输出其它内容就会将原内容覆盖. import time import sys def progress_test(): bar_length= ...
- Intellj IDEA Java随笔
敲击sout+Tab会出现:System.out.println(); int(-2147483648, 2147483647) 当一个方法类型不是void时,那么我们不仅要考虑它正确时的返回值,错误 ...
- Cisco ASA 配置案例---anyconnect拨通后所有流量从服务器端出去
一.目的: 1.Cisco ASA之Lan端能正常上网. 2.anyconnect端所有流量从Cisco ASA的Outside出去. 3.anyconnect端能访问Cisco ASA的Inside ...
- Appium常用的API函数
在学习应用一个框架之前,应该了解一下这个框架的整体结构或是相应的API函数.这篇文章还不错:http://blog.sina.com.cn/s/blog_68f262210102vzf9.html,就 ...
- The file couldn't be opened because you don't have permission to view it
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...