I'm trying to wrap a class from a library I'm using in Lua. Specifially, I'm trying to wrap the color class from SFML. The full source for the color class can be seen here and here.
我正在尝试从我在Lua中使用的库中包装一个类。特别是,我正在尝试从SFML中包装颜色类。在这里和这里可以看到颜色类的完整源代码。
This is the function that's that I'm failing in.
这就是我失败的功能。
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;
}
And this is the error
这就是错误
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
I do similar things in a few other places without running into this error, so I'm not sure what would be causing it. Looking at the Color's source code I don't see anything weird or out of the ordinary, and I've run out of ideas. I've also tried using the default constructor (i.e. no arguments) and then just setting the value afterward, but that didn't do any good either.
我在其他几个地方做类似的事情而没有遇到这个错误,所以我不确定是什么原因导致它。看看Color的源代码,我没有看到任何奇怪或不寻常的东西,而且我已经没有想法了。我也尝试使用默认构造函数(即没有参数),然后只是设置值,但这也没有任何好处。
1 个解决方案
#1
61
To use the standard placement form of new
you have to #include <new>
.
要使用新的标准放置形式,您必须#include
The form of new
that you are using requires a declaration of void* operator new(std::size_t, void*) throw();
.
您正在使用的新形式需要声明void * operator new(std :: size_t,void *)throw();.
You don't have to #include <new>
to use non-placement new
.
您不必使用#include
#1
61
To use the standard placement form of new
you have to #include <new>
.
要使用新的标准放置形式,您必须#include
The form of new
that you are using requires a declaration of void* operator new(std::size_t, void*) throw();
.
您正在使用的新形式需要声明void * operator new(std :: size_t,void *)throw();.
You don't have to #include <new>
to use non-placement new
.
您不必使用#include