Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

c++ - No matching function for call to operator new

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.

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.

question from:https://stackoverflow.com/questions/3156778/no-matching-function-for-call-to-operator-new

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To use the standard placement form of new you have to #include <new>.

The form of new that you are using requires a declaration of void* operator new(std::size_t, void*) throw();.

You don't have to #include <new> to use non-placement new.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...