Yes, that would work. There is a way to make the code a bit cleaner, and that's through using a smart pointer like std::unique_ptr.
Example using std::unique_ptr:
struct SYSMENUITEM{
SYSMENUITEM();
~SYSMENUITEM();
string ID;
string Name;
int Action;
//SYSMENUITEM *Branch;
//SYSMENUITEM *Next;
std::unique_ptr<SYSMENUITEM*> Branch;
std::unique_ptr<SYSMENUITEM*> Next;
};
SYSMENUITEM::SYSMENUITEM(){
Branch.reset(NULL);
Next.reset(NULL);
}
SYSMENUITEM::~SYSMENUITEM(){
//No need for these lines of code, pointers held by Branch and Next will be deleted when the object is destroyed(goes out of scope or deleted).
//if (Branch!=NULL) delete Branch;
//if (Next!=NULL) delete Next;
}
to use it:
SYSMENUITEM SM;
SM.Next.reset(new SYSMENUITEM);
SM.Branch.reset(new SYSMENUITEM);
Quote: "if I make a variable:
SYSMENUITEM SM;
and do this:
SM.Next=new SYSMENUITEM;
SM.Branch=new SYSMENUITEM;
then I delete the original:
delete SM;"
That might not work, because you can't 'delete' a regular variable. You'd have to let it go out of scope.
P.S. I'm a bit rushed for time, so some of this might not work or not make sense.