Don't work with raw pointers yourself if you don't need to.
If every HUD actually does use "the same" font (logically, even if they aren't currently the same freetype::font_data instance), then make a static member of the class instead (so that all instances can share it). You can initialize on first use like so (since freetype isn't using RAII properly):
class HUD { // other stuff static freetype::font_data theHUDFont; static bool inited; HUD() { if (!inited) { inited = true; theHUDFont.init("test.ttf", 16); } // other stuff } // other stuff};// Initialize the statics.static freetype::font_data HUD::theHUDFont;static bool HUD::inited = false;
Otherwise, strongly consider using smart pointers such as boost::shared_ptr, which actually is exactly the right model for this situation. (This will also cover you if you need to call some kind of 'uninit()' function.)
On the other hand, if every HUD in the final configuration logically has "its own" font, and you're just having problems setting up the tree structure, then you don't need anything like that, either. Instead, just change your interface. For example:
// Make this one *private*HUD::HUD() {}HUD::HUD(XY pos, XY size, const string& fontname, int fontsize) { // set position and size, and init the font.}HUD::addChild(XY pos, XY size, const string& fontname, int fontsize) { HUD child; // set position and size of the child. children.push_back(child); // Now get a reference to (alias of) the copy that was pushed back... HUD& added; // and init *its* font.}