[問題] G++ and VC++ Constructor 問題

作者: ROGZ (ROGZ)   2017-06-01 21:04:00
開發平台(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";
}

Links booklink

Contact Us: admin [ a t ] ucptt.com