我是新手在 c + +,并尝试创建类看起来像:
I'm novice in c++ and trying to create class looking like:
public ref class Klient { public: Klient(){} // zmienne static DWORD klienty[41][2]; static int i = 1; static DWORD* pid; static HANDLE* handle; //funkcje };但MSV说:
error C4368: cannot define 'klienty' as a member of managed 'Klient': mixed types are not supported此代码有什么问题?
推荐答案您可以将.NET基本数据类型作为成员你的托管类(static int i),或指向非托管的任何指针(DWORD * pid,HANDLE * handle),但是你不允许直接有一个非托管对象,整数数组作为一个非托管对象目的。
You can have .NET basic data types as members of your managed class (static int i), or pointers to anything unmanaged (DWORD* pid, HANDLE* handle), but you're not allowed to have an unmanaged object directly, and the array of integers counts as an unmanaged object for this purpose.
由于这里唯一提供问题的是非托管数组,因此可以将其切换到托管数组。
Since the only item giving you a problem here is the unmanaged array, you could switch it to a managed array.
public ref class Klient { public: Klient(){} // zmienne static array<DWORD,2>^ klienty = gcnew array<DWORD,2>(41,2); static int i = 1; static DWORD* pid; static HANDLE* handle; //funkcje };或者,你可以声明一个非托管类,在那里放任何你需要的,到它从托管类。 (如果你在非静态上下文中这样做,不要忘记从你的终结器中删除非托管内存。)
Or, you can declare a unmanaged class, put whatever you need to in there, and have a pointer to it from the managed class. (If you do this in a non-static context, don't forget to delete the unmanaged memory from your finalizer.)
public class HolderOfUnmanagedStuff { public: DWORD klienty[41][2]; int i; DWORD* pid; HANDLE* handle; HolderOfUnmanagedStuff() { i = 1; } }; public ref class Klient { public: Klient(){} // zmienne static HolderOfUnmanagedStuff* unmanagedStuff = new HolderOfUnmanagedStuff(); //funkcje };更多推荐
非托管var作为托管类c ++的成员
发布评论