学习C++ Primer这本书,在敲练习1.20的时候出现这样的错误
In file included from test.cpp:2:0:
Sales_item.h:56:20: 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
右键点击runcode,将
cd "/home/cf/VS-code-c/" && -std=c++11 pratice.cpp -o pratice && "/home/cf/VS-code-c/"pratice
改为
cd "/home/cf/VS-code-c/" && -std=c++11 pratice.cpp -o pratice && "/home/cf/VS-code-c/"pratice
即可运行