zoukankan      html  css  js  c++  java
  • 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:usersluli1documentsvisual studio 2013projectsconsoleapplication3header1.h(4): error C2220: warning treated as error - no 'object' file generated
    1>c:usersluli1documentsvisual studio 2013projectsconsoleapplication3header1.h(4): warning C4510: 'My' : default constructor could not be generated
    1> c:usersluli1documentsvisual studio 2013projectsconsoleapplication3header1.h(2) : see declaration of 'My'
    1>c:usersluli1documentsvisual studio 2013projectsconsoleapplication3header1.h(4): warning C4512: 'My' : assignment operator could not be generated
    1> c:usersluli1documentsvisual studio 2013projectsconsoleapplication3header1.h(2) : see declaration of 'My'
    1>c:usersluli1documentsvisual studio 2013projectsconsoleapplication3header1.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... :)

  • 相关阅读:
    android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存
    Web前端框架与类库的思考
    android应用开发(十):widget的使用
    响应式WEB设计的9项基本原则
    谈一下关于CQRS架构如何实现高性能
    迪杰斯特拉算法——PAT 1003
    Android开发-SQLite数据库
    寻找水王(2)
    PAT-1003
    PAT-1002
  • 原文地址:https://www.cnblogs.com/sunny-li/p/5823708.html
Copyright © 2011-2022 走看看