Results 1 to 2 of 2

Thread: using void in Qt Constructor and Destructor

  1. #1
    Join Date
    Sep 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default using void in Qt Constructor and Destructor

    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.

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using void in Qt Constructor and Destructor

    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.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. The following user says thank you to sonulohani for this useful post:

    iamDAMON (8th October 2012)

Similar Threads

  1. Replies: 12
    Last Post: 8th July 2011, 05:23
  2. Replies: 4
    Last Post: 9th September 2009, 09:02
  3. error: void value not ignored as it ought to be
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2008, 16:17
  4. QTextOStream and void*
    By mclark in forum Newbie
    Replies: 4
    Last Post: 7th August 2006, 18:40
  5. diffrence between void and virtual void
    By raphaelf in forum General Programming
    Replies: 2
    Last Post: 23rd February 2006, 13:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.