I am trying to make a GUI library. And I wish the following statement valid. Plus the user does not responsible for releasing memory.
// Create a GUI context
xGUI::xGUI gui(800, 600);
// gui.objects is a std::map<std::string, IWidget *>
gui.objects["btn"] = new xGUI::Button("Close", 50, 50);
gui.objects["btn2"] = gui.objects["btn2"]->clone();
// Block end gui will free all the objects.
As you can see, clone is ugly but needed.(Is there any solution?) However this clone will use new to allocate memory in the library. then be free by dtor of xGUI which I wrote in header file. new in the library and delete in the main program... Will it be a problem??
Aucun commentaire:
Enregistrer un commentaire