C++ Primer warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11

Sales_item.h:56:18: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
     Sales_item()=default;
                  ^
Sales_item.h:70:27: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
     unsigned units_sold = 0; // explicitly initialized
                           ^
Sales_item.h:71:22: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
     double revenue = 0.0;
                      ^
Sales_item.h:45:7: error: constructor required before non-static data member for ‘Sales_item::units_sold’ has been parsed
 class Sales_item {
       ^
Sales_item.h:45:7: error: constructor required before non-static data member for ‘Sales_item::revenue’ has been parsed

在敲练习的时候,出现的以上错误提示。应该是C++11才支持defaulted and deleted functions的用法。

解决方法:

sudo vim ~/.bashrc

然后输入密码。

在第90行, # some more ls aliases添加下面内容:

alias g++11='g++ -g -Wall -std=c++11'
alias g++14='g++ -g -Wall -std=c++14'

相当于起别名。

你可能感兴趣的:(C++)