I am trying to use shared_ptr to control the lifetime of some CEGUI objects (Renderer,System, ResourceProvider).
Here I am constucting a shared_ptr for the System object:
Code: Select all
ceguiSystem = std::shared_ptr<CEGUI::System>(
&CEGUI::System::create(*openGLRenderer, resourceProvider.get()), //get the raw pointer here
CEGUI::System::destroy // use this custom deleter
);
Which works fine.
But for the renderer classes, not so much.
I have to use a lambda expression, because I have to call the destroy() method with a parameter:
Code: Select all
openGLRenderer = std::shared_ptr<CEGUI::OpenGLRenderer>(
&(CEGUI::OpenGLRenderer::create()), // get raw pointer here
[](CEGUI::OpenGLRenderer * ptr) // lambda expression
{
CEGUI::OpenGLRenderer::destroy(*ptr); // call the custom deleter with argument the object
}
);
(fails to compile with error C2197: 'void (__cdecl *)(void)': too many arguments for call)
The syntax should be fine - take this self contained example:
Code: Select all
#include <memory>
class SomeClass
{
public:
static void destroy(SomeClass& a) {}
};
std::shared_ptr<SomeClass> sPtr;
int main()
{
SomeClass a;
sPtr = std::shared_ptr<SomeClass>(
&a,
[](SomeClass* a)
{
SomeClass::destroy(*a);
}
);
return 0;
}
I can't find any differences between the two, but one of them is not compiling.