看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) G++,VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 下面的程式碼在VC++可以編譯,但在g++就會出現問題,g++會 用const char*去做construct,但為什麼VC++就不會出現錯誤? 找一下網路,有人用下面這樣就可以了 A(const char* s) { x = s; } 但我想問一下,string直接給char*,為什麼string 可以抓到正確的陣列位數? 以及這樣寫會有問題嗎? 謝謝!! class A { private: string x; public: A(string s) { x = s; } }; int main() { A a = "123"; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.118.150.41 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1496322242.A.BC5.html