Results 1 to 4 of 4

Thread: destructor dilemma

  1. #1
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default destructor dilemma

    Here is class for rational numbers
    Qt Code:
    1. #ifndef RATIONAL_H
    2. #define RATIONAL_H
    3.  
    4. class rational{
    5. public:
    6. rational(short =0,short=0,short=0, short=0);
    7. ~rational();
    8. void setRational(short =0,short=0,short=0, short=0);
    9. void Add();
    10. void Subtract();
    11. void Multiply();
    12. void Divide();
    13. void PrettyPrint(char ch);
    14. void floatPrint();
    15. private:
    16. short r1;
    17. short r2;
    18. short r3;
    19. short r4;
    20. };
    21. #endif // RATIONAL_H
    To copy to clipboard, switch view to plain text mode 

    Upon compiling I get an error for my destructor:
    H:\C++_How_To_Program\chap06\rational_numbers/main.cpp:101: undefined reference to `rational::~rational()'

    This occurs in any class I create. I can't figure out why.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: destructor dilemma

    is the destructor implemented?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: destructor dilemma

    it has no implementation. I didn't think it needs it.
    Last edited by Petr_Kropotkin; 17th March 2010 at 16:09.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: destructor dilemma

    If you declare a destructor, it needs to be implemented. If you don't declare a destructor, the compiler will create one for you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Destructor not being called
    By vieraci in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2012, 15:06
  2. QTemporaryFile and his destructor
    By SABROG in forum Qt Programming
    Replies: 3
    Last Post: 19th May 2009, 19:55
  3. Destructor in QT
    By hgedek in forum Newbie
    Replies: 1
    Last Post: 18th September 2007, 10:54
  4. Caching QAbstractProxyModel dilemma
    By Alessandro in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2006, 19:51
  5. QMap destructor bug
    By Ruud in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2006, 09:08

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.