const member in struct cause warning 4510

---恢复内容开始---

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 is to 

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

 

---恢复内容结束---

posted @ 2016-08-30 21:27  sunny,lee  阅读(116)  评论(0)    收藏  举报