0
請幫助我,爲什麼我的代碼無法編譯, 編譯器會抱怨說: 錯誤C2629:意外的「StringToAnsi(」 錯誤C2334:「{」的前面有意外標記;跳過明顯的函數體 錯誤C2629:意外的「StringToAnsi(」 ... 這裏是我的代碼:c + +託管類構造函數不能有參數?
#using <System.dll>
#using <mscorlib.dll>
class StringToAnsi
{
private:
void * m_ptr;
public:
StringToAnsi(System::Object^str)
{
m_ptr = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(safe_cast<System::String^>(str)).ToPointer();
}
StringToAnsi(System::String^str)
{
m_ptr = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str).ToPointer();
}
~StringToAnsi()
{
System::Runtime::InteropServices::Marshal::FreeHGlobal(System::IntPtr(m_ptr));
}
operator const ACHAR*()
{
return (const ACHAR*)m_ptr;
}
您可以嘗試翻譯錯誤消息嗎? – 2011-03-17 15:05:27
我不知道什麼前面有意外標記的意思是:S – 2011-03-17 15:06:46
對不起這裏的每一個人,我使用vc7.0並且第一次寫混合代碼,指針是*但不是^,就是這樣 – learner 2011-03-22 08:00:05