1234567891011
Menu* CreateItem() { Menu* menuPointer = new Menu; //initialize values return menuPointer; } void AnotherFunction() { Menu* lastItem = CreateItem(); }
1234567891011121314151617181920
class Menu { public: Menu(){} ~Menu(){} }; Menu* CreateMenu() { Menu* menuPointer = new Menu; return menuPointer; } int main() { Menu* menu = CreateMenu(); return 0; }
12345678910111213141516171819202122232425262728
Menu* Content::CreateItem() { Menu* menuPointer = new Menu; //initialize values return menuPointer; } void Content::CreateObject(Menu* curItem, Menu* lastItem) { lastItem = CreateItem(); curItem = lastItem; } void Content::Initialize() { Menu* curItem = 0; Menu* lastItem = 0; while (...) { if (/*object is complete*/) { CreateObject(curItem, lastItem); } //create object little by little } }
12
Menu* curItem = 0; Menu* lastItem = 0;
Menu* curItem = new Menu; Menu* lastItem = new Menu;