c++ - Is using "this" in contructor's initialization list specificly dangerous with Qt? -


i need reliable information "this" subject:

class myclass, public qwidget { public:     myclass( qwidget * parent = null )          :qwidget( parent ),          mpanotherwidget( new qwidget( ) ){}; private:     qwidget * mpanotherwidget; }; 

of course, calling virtual functions in contructor or initialization list bad idea. question is: can code

mpanotherwidget( new qwidget( ) ) 

lead undefined behavior?! , if so: why ?

please quote sources if can! thanks!

it depends on qwidget pointer given. fine pass around reference or pointer half-constructed object long called code not access underlying object. need documentation of qwidget know whether touches object or stores pointer.


in particular case of qt, reading documentation, calling constructor of qwidget, argument of type qwidget*, , this used cast base pointer. obtaining pointer base guaranteed in 12.7/3 requirement conversion the construction of x , construction of of direct or indirect bases directly or indirectly derive b shall have started. pointer passed qwidget constructor may use in way wants, since constructor base qwidget has completed before constructor mpanotherwidget starts.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -