c++ - How to declare a function which creates an object which will never be null? -


i have function creates object qmenu (in heap)

qmenu* createmenu(qwidget* parent); // parent takes ownership of menu 

the function never return null pointer. think declaration don't tell point because returns pointer. when using method, need

if (qmenu* m = createmenu(parent))     m->... 

which annoying. if returns reference, tells point.

qmenu& createa(qwidget* parent); 

i never see code declares way. okay? there better declaration point?

yes, it's fine return created object reference, if function makes own arrangements ownership of object's lifetime.

one big example of function this: v& std::map<k,v>::operator[](const k&);.


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -