如何转换 C++ Xcode 中的 Objective C 来编译 Box2D?
尝试将 Box2D 用于 Iphone 应用程序,但不知道如何将以下 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);
}
Trying to use Box2D for an Iphone App but do not know how to convert the following C++ header file to Xcode Objective C... Would someone please help me? Thank You in Advance!
#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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了标头之外,所有代码都是 C,而不是 C++。例如,
malloc
/free
是 C 例程。 C++ 中最接近的例程是new
/delete
。除非您没有向我们展示其他代码,否则您应该能够简单而安全地指向 C 标头,而不是:
...并且该代码块应该编译为 C(因此在 Objective-C 项目中)。
Except for the headers, all of that code is C, not C++. For example,
malloc
/free
are C routines. The nearest routines in C++ would benew
/delete
.Unless there is other code you're not showing us, you should be able to simply and safely point to C headers, instead:
...and that chunk of code should compile as C (and therefore within an Objective-C project).
你尝试过 Objective-C++ 模式吗?将
.m
/.cpp
文件重命名为.mm
Did you try Objective-C++ mode? Rename your
.m
/.cpp
files to.mm