Results 1 to 6 of 6

Thread: virtual function

  1. #1
    Join Date
    Aug 2009
    Posts
    30
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default virtual function

    I tried to compile a class with virtual functions and qtcreator want only compile the functions inside the header. I cannot compîle when the functions are in the cpp file. The compilator says the vtable is not defined.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: virtual function

    can you show some code?

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

    shenakan (25th August 2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    30
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: virtual function

    Qt Code:
    1. #ifndef PATH_H
    2. #define PATH_H
    3.  
    4. #include <fstream>
    5. #include <iostream>
    6. #include <sstream>
    7. #include <iomanip>
    8.  
    9. using namespace std;
    10.  
    11. class Path{
    12. protected:
    13.  
    14. public:
    15. virtual double getOrientation() const;
    16. };
    17.  
    18. #ifndef TRANSIT_H
    19. #define TRANSIT_H
    20.  
    21.  
    22. #include <iomanip>
    23. #include <fstream>
    24. #include <iostream>
    25. #include <string.h>
    26. #include "path.h"
    27.  
    28.  
    29. using namespace std;
    30.  
    31. class Transit : public Path{
    32.  
    33. public:
    34. Transit(const char *info);
    35.  
    36. double getOrientation() const;
    37. };
    38. #endif
    To copy to clipboard, switch view to plain text mode 

    I get this message : undefined reference to "vtable for Path"

  5. #4
    Join Date
    Aug 2009
    Posts
    30
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: virtual function

    ok I found my problem. I forgot to add =0 at the end of my virtual function and also a const in one of function of the derivated class.

    Qt Code:
    1. virtual double getOrientation() const = 0;
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: virtual function

    the defination looks alrite to me.... are you defining function in both the classes?
    EDIT: - too late

  7. #6
    Join Date
    Aug 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: virtual function

    If you don't want the "getOrientation()" method to be virtual pure ( = 0 ), you could also define a virtual destructor for the Path class.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.