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 ...
随机推荐
- Unity3d之个性化皮肤
1.首先创建皮肤,贴图 2.在代码中定义public GUISkin变量,在Inspector中赋值 3.在OnGUI中调用 GUI.skin = mySkin; GUI.Button(new Rec ...
- 鼠标滚动div固定浮动-加锚点
页面: <div class="pa"> <div class="w-95-sl bdl-2"><a>标 ...
- JSTL标签库的使用
首先是四大标签库 核心 标签库 <%@ taglib uri="http://java.sun.com/jsp/jstl/core"%> 格式标签库 <%@ ta ...
- android:installLocation 解析
决定了apk安装位置 有三个选项:1.auto 2.internalOnly 3.preferExternal http://www.cnblogs.com/Lefter/archive/2012/0 ...
- 线程的2个ID
我们知道进程ID是操作系统调度的最小单位,有时候根据业务的需要,我们会使用到多线程技术,当创建了多个线程时,也会有一个线程ID,那这个线程ID和进程ID有什么不一样吗? 其中,线程组的线程ID是属于N ...
- UE4蓝图编程的第一步
认识UE4蓝图中颜色与变量类型: UE4中各个颜色对应着不同的变量,连接点和连线的颜色都在表示此处是什么类型的变量.对于初学者来说一开始看到那么多连接点, 可能会很茫然,搞不清还怎么连,如果知道了颜色 ...
- javac找不到或无法加载主类 com.sun.tools.javac.Main
在安装jdk后或者以前安装了jdk某时使用javac编译java文件时出现找不到或无法加载主类com.sun.tools.javac.Main,这个问题时,网上一般都说是环境变量配置不对,这样的说法其 ...
- HTML5的form表单属性
form:HTML4中,表单内的从属元素必须书写在<form></form>之内,但是在HTML5中,表单的从属元素可以处于页面的任何位置,然后为其添加form属性,属性值为f ...
- OD调试15
可以达到不脱壳的妙用.含义:把补丁写入程序代码,就叫内嵌补丁 那我们先看看今天的程序 是一个写DVD目录的程序,点continue就可以进入使用了 发现一个还有29天 就过期了 ,点en ...
- vb小程序浅析
系统 : Windows xp 程序 : BJCM10B 程序下载地址 :http://pan.baidu.com/s/1dFyXe29 要求 : 编写注册机 使用工具 : OD 可在看雪论坛中查找关 ...