PDA

View Full Version : constructor declaration



BalaQT
6th July 2011, 07:29
Dear experts,

Just a quick question,

1) In constructor declaration, which is better


myClass(QWidget *pParent = 0)
or

myClass(QWidget *pParent = NULL)

2)and shall I check like the following? (comparing integer and pointer?)

if ( 0 == qApp->activeModalWidget())


Thanks,
Bala

Santosh Reddy
6th July 2011, 07:58
better be consistent, use 0, both in ctor and comparison.

If need to use NULL macro due to existing code, use NULL for comparing all the objects which are based on existing code. What I mean to is be constant in using them, i.e don't mix them.

eq: if class A ctor is using 0, then compare all objects / pointers of class A with 0
if class B ctor is using NULL, then compare all objects / pointer of class B with NULL

BalaQT
6th July 2011, 10:00
better be consistent, use 0, both in ctor and comparison.

If need to use NULL macro due to existing code, use NULL for comparing all the objects which are based on existing code. What I mean to is be constant in using them, i.e don't mix them.

eq: if class A ctor is using 0, then compare all objects / pointers of class A with 0
if class B ctor is using NULL, then compare all objects / pointer of class B with NULL
Thanks for the reply,

So, its safe to use

if ( 0 == qApp->activeModalWidget())

Thanks,
Bala