什麼這個是錯的:如何在C++/CLI中定義一個字符串數組?
我得到這些錯誤所有5個定義:
error C3698: 'System::String ^' : cannot use this type as argument of 'gcnew'
error C2512: 'System::String::String' : no appropriate default constructor available
array<String^>^ arr = gcnew array<String^>
{
gcnew String^ "Madam I'm Adam.",
gcnew String^ "Don't cry for me,Marge and Tina.", //error C2143: syntax error : missing '}' before 'string' AND error C2143: syntax error : missing ';' before 'string'
gcnew String^ "Lid off a daffodil.",
gcnew String^ "Red lost Soldier.",
gcnew String^ "Cigar? Toss it in a can. It is so tragic."
}
這裏的構造函數是什麼,在C++/cli中?我知道在C++中它會在創建對象時調用,但是可以解釋它在這裏以及它的作用。 – Ghost
構造函數在C++,C++/CLI和C#中具有相同的含義和功能。在所有情況下,在分配原始內存之後,由new/gcnew調用它來執行初始化。 –
@David:實際上,構造函數在.NET和標準C++中的表現完全不同。它們具有相同的目的,但是在施工過程中虛擬調度等細節的運行方式卻非常不同。 –