Monday, 26 August 2013

How do I clean up the classes properly in Lua and C++?

How do I clean up the classes properly in Lua and C++?

I have used Luabind to bind a class to Lua. I need to make sure the class
is correctly disposed of when it is destructed or made null through
myClass = nil.
This class adds itself to a static list inside itself like this:
template<typename T>
class component : public componentInterface
{
public:
static std::list<componentInterface *> list;
component() : componentInterface()
{
di::component<T>::list.push_back(this);
}
~component()
{
di::component<T>::list.remove(this);
}
};
And when the destructor is called it promptly removes itself from the list.

No comments:

Post a Comment