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的更多相关文章

  1. C++ 之const Member Functions

    Extraction from C++ primer 5th Edition 7.1.2 The purpose of the const that follows the parameter lis ...

  2. [C++] static member variable and static const member variable

    static member variable[可读可写] 可以通过指针间接修改变量的值 static const member variable[只读] 压根就不可以修改变量的值,会报错

  3. C++ Data Member内存布局

    如果一个类只定义了类名,没定义任何方法和字段,如class A{};那么class A的每个实例占用1个字节的内存,编译器会会在这个其实例中安插一个char,以保证每个A实例在内存中有唯一的地址,如A ...

  4. C++ c++与C语言的区别(三目运算符,const修饰符)

    //区别⑦:三目运算符(C++版本) #include<iostream> using namespace std; //三目运算符 C语言返回变量的值 C++语言是返回变量本身 void ...

  5. C++11 关键字 const 到底怎么用?

    Const 的作用及历史 const (computer programming) - Wikipedia 一.历史 按理来说,要想了解一件事物提出的原因,最好的办法就是去寻找当时的历史背景,以及围绕 ...

  6. C指针-const char* p到底是什么不可以改变

    char a = 'w'; char b = 'q'; const char* p = &a; p = &b; printf("%c",p[0]); 如上一段代码, ...

  7. struct内存对齐1:gcc与VC的差别

    struct内存对齐:gcc与VC的差别 内存对齐是编译器为了便于CPU快速访问而采用的一项技术,对于不同的编译器有不同的处理方法. Win32平台下的微软VC编译器在默认情况下采用如下的对齐规则:  ...

  8. const成员函数

    尽管函数名和参数列表都相同,void foo( ) const成员函数是可以与void foo( )并存的,可以形成重载! 我们假设调用语句为obj.foo(),如果obj为non-const对象,则 ...

  9. c++ const总结

    [本文链接] http://www.cnblogs.com/hellogiser/p/cplusplus-const-summay.html 看到const 关键字,C++程序员首先想到的可能是con ...

随机推荐

  1. 项目中踩过的坑之-sessionStorage

    总想写点什么,却不知道从何写起,那就从项目中踩过的坑开始吧,希望能给可能碰到相同问题的小伙伴一点帮助. 项目情景: 有一个id,要求通过当前网页打开一个新页面(不是当前页面),并把id传给打开的新页面 ...

  2. select跳转页面

    跳转到当前页: <select name="here " onchange="location.href=this.options[this.selectedInd ...

  3. HTML <label> 标签

    定义:<label> 标签为 input 元素定义标注(标记). 用法: label 元素不会向用户呈现任何特殊效果.不过,它为鼠标用户改进了可用性.如果您在 label 元素内点击文本, ...

  4. CheckBoxList控件获取多选择,需要遍历

    CheckBoxList控件获取多选择,需要遍历,环境:vs2008 在页面上添加CheckBoxList控件,输入项值 a,b,c,d.然后添加按钮 Button2确定,如何获取CheckBoxLi ...

  5. WPF环境下多点触屏开发的一些经验(转)

    本系列将介绍Multi-Touch(MT)多点触控技术的相关内容,使开发人员了解如何在Windows 平台中开发出具有MT 功能的应用程序.众所周知Windows 7 操作系统自身已经支持具有MT 功 ...

  6. mongo 导入json数据

    删除库以及导入库

  7. :before :after

    CSS 有两个说不上常用的伪类 :before 和 :after,偶尔会被人用来添加些自定义格式什么的,但是它们的功用不仅于此.前几天发现了 Creative Link Effects 这个非常有意思 ...

  8. win8设置保护眼睛的颜色

    win8下打开注册表编辑器(win键+R,即运行,输入regedit),依次双击打开HKEY_CURRENT_USER\Control Panel\Colors\,将Window的键值修改为204 2 ...

  9. 学习Core 本机开发调试 (环境)

    安装  https://www.microsoft.com/net/download 本机开发调试 需要下载安装这3个,如果没装 windows(Server Hosting)可能会 出现502.5报 ...

  10. Designing for iOS: Graphics & Performance

    http://robots.thoughtbot.com/designing-for-ios-graphics-performance  [原文] In the previous article, w ...