1
我無法找到此問題的原因。指向c風格字符串的指針數組的指針C++/cli
功能getfruits指針返回到c樣式字符串pointes的陣列。 主要嘗試訪問c樣式的字符串。
using namespace System;
#pragma managed
void getfruits(char ***list, int* count)
{
char *txt[] =
{
"apple",
"orange",
"pears",
"banana",
};
*list = txt;
*count = 4;
}
#pragma managed
int main(array<System::String ^> ^args)
{
char **lst; int cnt;
getfruits(&lst,&cnt);
char *t; int i;
String^ s;
for (i=0; i<cnt; i++)
{
t = lst[i]; //t = <undefined value>
s = gcnew String(t);
Console::WriteLine("Fruit = {0}", s);
};
Console::ReadKey();
return 0;
}
但它變得,而不是指向C風格的字符串。
最終,
型 'System.AccessViolationException' 未處理的異常發生在arraysandclasses.exe
其他信息:試圖讀取或寫入保護內存。這通常表明其他內存已損壞。
怎麼回事?有人能指出什麼嗎?代碼應該簡單地編譯,如果複製和粘貼。提前致謝。