[問題] nullptr was not declared in this scope

看板C_and_CPP (C/C++)作者 (我所知道的只有一件事)時間12年前 (2013/08/02 17:26), 編輯推噓2(204)
留言6則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) linux mint 13(Maya) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 應該沒有 問題(Question): 我最近在自學c++,用的書是c++ primer fifth edition,最近看到pointer上有一段寫 int *p1 = nullptr,但是我自己用g++ compile不會過??而且一直找不到原因 g++的版本:gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 餵入的資料(Input): 錯誤結果(Wrong Output): a.cc: In function ‘int main()’: a.cc:5:9: error: ‘nullptr’ was not declared in this scope 程式碼(Code):(請善用置底文網頁, 記得排版) #include<iostream> #include <cstdlib> int main() { int *p0=nullptr; int *p1=0; int *p2=NULL; return 0; } 補充說明(Supplement): 苦惱很久,請大家幫幫忙 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.101.91

08/02 17:27, , 1F
nullptr是新功能 gcc要用比較新的
08/02 17:27, 1F

08/02 17:29, , 2F
-std=c++11 or -std=c++0x
08/02 17:29, 2F

08/02 17:30, , 3F
4.6夠新了. Compile的時候加個-std=c++11或-std=c++0x
08/02 17:30, 3F

08/02 17:31, , 4F
樓上可以講詳細一點嗎?linux系統好像沒這指令
08/02 17:31, 4F

08/02 17:31, , 5F
我試試看,謝謝
08/02 17:31, 5F

08/02 17:32, , 6F
可以了,感謝
08/02 17:32, 6F
文章代碼(AID): #1H-tjTAl (C_and_CPP)
文章代碼(AID): #1H-tjTAl (C_and_CPP)