什么是C ++ 11扩展[-Wc ++ 11-extensions] [英] What is a C++11 extension [-Wc++11-extensions]

查看:547
本文介绍了什么是C ++ 11扩展[-Wc ++ 11-extensions]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来了解发生此错误的位置:

I need some help understanding where this error is occurring:


警告:非静态数据成员的类内初始化是C ++ 11扩展[-Wc ++ 11-extensions]

warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]

这是它来自的代码部分:

This is the section of the code that it is coming from:

typedef struct Hand {
    bool straight = false;
    bool flush = false;
    bool four = false;
    bool three = false;
    int pairs = 0;
    } Hand;


推荐答案

这不是错误,是警告。它告诉您,仅允许初始化以C ++ 11标准(之所以称呼,因为它于2011年发布)开始的struct / class的非静态成员。在此之前,C ++ 98并没有正式允许您这样做(您猜想它是在1998年出版的)。长话短说,您的操作在2011年才成为合法的官方C ++。编译器的默认似乎是1998年的标准。

That's not an error, it's a warning. It tells you that you're only allowed to initialize non-static members of a struct / class starting with the C++11 standard (so called because it was published in 2011). Before that, you weren't officially allowed to by C++98 (published, you've guessed it, in 1998). Long story short, what you're doing has only become legal, official C++ in 2011. Your compiler's default seems to be the 1998 standard.

尝试使用<$ c进行编译$ c> -std = c ++ 11 作为命令行标志(假设您使用的是GCC或clang),警告应该消失了。如果您使用的是其他编译器,则还应该有一个标志(如果它足够新,可以实现C ++ 11)。

Try compiling with -std=c++11 as a command line flag (assuming you're using GCC or clang), and the warning should go away. If you're using a different compiler, there should be a flag for that as well (if it's recent enough to implement C++11).

这篇关于什么是C ++ 11扩展[-Wc ++ 11-extensions]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆