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. js倒计时显示

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>j ...

  2. 【python】错误/异常处理,调试,测试

    try: print('try') r=10/2 print('result is:',r) #发生错误,会执行这部分 except ValueError as e: print('ValueErro ...

  3. 2014年7月份第1周51Aspx源码发布详情

      QF万能视频播放器源码  2014-6-30 [VS2010]本源码是一个万能视频播放器源码.可实现各种格式的影片播放功能. 1.点击[开始]按钮,弹出窗口,选择影片路径,确定后即可播放.可拖拽滚 ...

  4. 关于jetty项目中的问题.

    在某台虚拟机上部署的项目出现的问题: 我想要更改定义的owl文件,重启服务器,却打不开网页. 1.couldnot found owl ,然后我拷贝一份owl到work/config目录下,继续更改配 ...

  5. CGBitmapContextCreate函数参数详解

    函数原型: CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerCo ...

  6. java 接口

    1.接口的引出:发现没有继承关系的类也能共享行为 2.接口不是类,类描述对象的属性和行为,但是接口只关注实现的行为3.当我们发现有行为在多个没有继承关系的类中共享,我们要把它抽取到接口中,而不是写到父 ...

  7. Java面向对象基础知识汇总

    OOP:Orient Object Programe AOP:Aspect Orient Programe 封装:Encapsulation 继承:Inheritance 多态:Polymorphmi ...

  8. BZOJ 3339 && BZOJ 3585 莫队+权值分块

    显然若一个数大于n就不可能是答案. #include <iostream> #include <cstring> #include <cstdio> #includ ...

  9. MAC按键以及快捷键

    使用普通的非Mac自带的键盘的同志们,想要在Mini Mac上面想要使用键盘,则推荐使用Mac系统自带的虚拟键盘,这样就可以查看普通键盘上每个键对应的Mac系统上是什么. 查看Mac系统上的虚拟键盘的 ...

  10. tabhost使用

    Tabhost用法 使用方法一:使用同一个布局文件 在xml中如此定义tabhost: <RelativeLayout xmlns:android="http://schemas.an ...