how use address operator on a class constructor?

my class menu have a constructor:
Menu(string caption, Menu *submenu=NULL, HWND MainHWND=WindowMain, bool systmenu=false)
how can i convert the submenu to address variable instead a pointer?
Not sure I understand. A pointer is an object that contains the memory address of some other object.
that constructor make me use it on these way:
Menu mnuFile("&File"), mnuExit("&Exit",&mnuFile);
the address operator before the mnuFile. can i change the Menu contructor for accept it without the address operator?
(but continueing with 1 default value)
You could make the second parameter a reference and then use the & operator inside the constructor to get the pointer instead.
 
Menu(string caption, Menu& submenu, HWND MainHWND=WindowMain, bool systmenu=false)

References can't be null so to allow all but the first argument to be left out you could add another constructor that only takes a string as argument.
 
Menu(string caption)
i'm sorry but what you think about:
Menu(string caption, Menu &submenu=*(Menu*)NULL, HWND MainHWND=WindowMain, bool systmenu=false)
?
but i don't know compare the value.
another question: being a pointer, i can use NULL, but why not with adress operator?
Null means the pointer is not pointing to a valid object. It is not allowed to dereference a null pointer. If you do, it means the behaviour is undefined so anything could happen.

If you need to handle null I really think you should use pointers. References are not the correct tool for the job. It isn't that much of a job having to type & when you pass the object, is it?
the problem isn't the job. but.. i did that class, but after sometime i was trying to use it, but i forget the '&', the compiler give me errors, but i was not understanding them :(
that's why i must do your 1st advice and overloading the constructor. it's the best.
i'm overloading the Menu() constructor. but the 1st parameter it's, always the same. why i get some errors?
Last edited on
error: "call of overloaded 'Menu(const char [10])' is ambiguous|"
seems now that i understand why.
we must, when overloading, avoid default values\parameters or we can get some errors
Menu(string caption, HMENU systemmenu, HWND window=ActivatedForm) Menu(string caption,HWND MainHWND=ActivatedForm) Menu(string caption, Menu &submenu, HWND MainHWND=ActivatedForm)
like you see, only the 3rd parameter have defult value. so no error.
i hope these information help more people that needs overloading functions
Topic archived. No new replies allowed.