PDA

View Full Version : using void in Qt Constructor and Destructor



iamDAMON
8th October 2012, 06:38
Hi Guys!

I have some question about constructor and destructor.
Please help me guys.
Can i use void before the function prototype of the constructor and destructor?

Here's the code:
ClassA.h
==================================
namespace Ui{
class ClassA
}

class ClassA: public QWidget{
Q_OBJECT
public:
explicit ClassA (QWidget *Parent = 0)
~ClassA(void);
private:
Ui::ClassA Ui;
};
==================================
ClassA.cpp
==================================
void ClassA::ClassA (QWidget *Parent)
QWidget(Parent),
Ui(new Ui::ClassA)
{
...
...
}

void ClassA::~ClassA(void)
{
delete Ui;
}
==================================

After compiling I have these errors:

return type specification for constructor is invalid
return type specification for destructor is invalid


Can you help me guys. Thanks in advance.

sonulohani
8th October 2012, 06:50
The signature of the constructor does not provide option for a return type. So, you cannot use void.

For a normal function/method signature is like so:-
<returntype> <function name> (<parameter list>)

but for a constructor its:-
<function name: same as class name>(<parameter list>)

void does not mean no returntype. it means nothing is returned.
void is actually a type in some cases not just the absence of a type. You can declare a pointer to type void.