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