【发布时间】:2010-07-01 10:05:17
【问题描述】:
我正在尝试从我在 Lua 中使用的库中包装一个类。具体来说,我正在尝试从 SFML 包装颜色类。颜色类的完整源代码可见here 和here。
这是我失败的功能。
int SFColor_new(lua_State* L)
{
// omitting part where I set r, g, b, and a
new (lua_newuserdata(L, sizeof(Color))) Color(r, g, b, a); // Line 47
luaL_getmetatable(L, LuaInfo<Color>::myMetaTableName);
lua_setmetatable(L, -2);
return 1;
}
这就是错误
LuaSFMLColor.cpp: In function ‘int ag::SFColor_new(lua_State*)’:
LuaSFMLColor.cpp:47: error: no matching function for call to ‘operator new(unsigned int, void*)’
<built-in>:0: note: candidates are: void* operator new(unsigned int)
make: *** [game] Error 1
我在其他几个地方做了类似的事情而没有遇到这个错误,所以我不确定是什么原因造成的。查看 Color 的源代码,我没有看到任何奇怪或不寻常的东西,而且我已经没有什么想法了。我也尝试过使用默认构造函数(即没有参数),然后只设置值,但这也没有任何好处。
【问题讨论】:
-
当时我并不知道。 :P
标签: c++ new-operator