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'

相當於起別名。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章