Как перевести класс на C++ в класс на С#? - C#
Формулировка задачи:
Доброго времени суток! Как перевести класс с C++ на C#? (Особенно интересует union)
Лучше сразу показать, кодом заранее спасибо!
struct asSFuncPtr
{
asSFuncPtr(asBYTE f = 0)
{
for( size_t n = 0; n < sizeof(ptr.dummy); n++ )
ptr.dummy[n] = 0;
flag = f;
}
void CopyMethodPtr(const void *mthdPtr, size_t size)
{
for( size_t n = 0; n < size; n++ )
ptr.dummy[n] = reinterpret_cast<const char *>(mthdPtr)[n];
}
union
{
// The largest known method point is 20 bytes (MSVC 64bit),
// but with 8byte alignment this becomes 24 bytes. So we need
// to be able to store at least that much.
char dummy[25];
struct {asMETHOD_t mthd; char dummy[25-sizeof(asMETHOD_t)];} m;
struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
} ptr;
asBYTE flag; // 1 = generic, 2 = global func, 3 = method
};Решение задачи: «Как перевести класс на C++ в класс на С#?»
textual
Листинг программы
struct asSMethodPtr
{
template<class M>
static asSFuncPtr Convert(M Mthd)
{
// This version of the function should never be executed, nor compiled,
// as it would mean that the size of the method pointer cannot be determined.
int ERROR_UnsupportedMethodPtr[N-100];
asSFuncPtr p(0);
return p;
}
};