C++編譯.cpp檔案,出現錯誤:
[sxl@VM-4-5-centos string]$ g++ -o mystring string.cpp
In file included from string.cpp:1:0:
string.h: In destructor ‘sxl::string::~string()’:
string.h:48:16: error: ‘nullptr’ was not declared in this scope
_str = nullptr;
解決方法一:編譯時加上-std=gnu++0x
[sxl@VM-4-5-centos string]$ g++ -std=gnu++0x string.cpp -o mystring
[sxl@VM-4-5-centos string]$ ./mystring
hello world
hello world
hello sxl
hello sxl
解決方法二:編譯時加上-std=c++11
[sxl@VM-4-5-centos string]$ g++ -std=c++11 string.cpp -o mystring
[sxl@VM-4-5-centos string]$ ./mystring
hello world
hello world
hello sxl
hello sxl
原因:g++版本不一樣,有些不支持nullptr,需要利用-std=來設定
具體設定可查看GCC 編譯標準-std=的設定方法
注意:在撰寫makefile檔案的時候也是這樣寫,一定要注意!!!
(我自己就犯了這個錯誤,試了好多次)
g++ -std=c++11 string.cpp -o mystring #mystring一定在-o之后,不然會造成不存在mystring檔案,會報錯
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/296762.html
標籤:其他
上一篇:超硬核!只需一篇萬字博客帶你掌握Hive??【小白還不趕緊收藏起來】
下一篇:2021-08-29 兩數相加
