0

Iphone アプリに Box2D を使用しようとしていますが、次の C++ ヘッダー ファイルを Xcode Objective C に変換する方法がわかりません...誰か助けてくれませんか? 前もって感謝します!

#include <Box2D/Common/b2Settings.h>
#include <cstdlib>
#include <cstdio>
#include <cstdarg>

b2Version b2_version = {2, 2, 1};

// Memory allocators. Modify these to use your own allocator.

void* b2Alloc(int32 size){
return malloc(size);
}

void b2Free(void* mem)
{
   free(mem);
}

// You can modify this to use your logging facility.

void b2Log(const char* string, ...)

{
   va_list args;
   va_start(args, string);
   vprintf(string, args);
   va_end(args);
}
4

2 に答える 2

2

ヘッダーを除いて、そのコードはすべて C++ ではなく C です。たとえば、malloc/freeは C ルーチンです。C++ で最も近いルーチンはnew/deleteです。

表示されていない他のコードがない限り、代わりに C ヘッダーを簡単かつ安全に指すことができるはずです。

#include <stdlib.h>   /* was #include <cstdlib> */
#include <stdio.h>    /* was #include <cstdio>  */
#include <stdarg.h>   /* was #include <cstdarg> */

...そして、そのコードのチャンクは C としてコンパイルする必要があります (したがって、Objective-C プロジェクト内で)。

于 2012-01-24T23:47:07.497 に答える
1

Objective-C++ モードを試しましたか? .m/.cppファイルの名前を次のように変更します.mm

于 2012-01-24T23:42:41.047 に答える