Results 1 to 3 of 3

Thread: Linker chokes on virtual methods

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Linker chokes on virtual methods

    I don't know if this is a Qt issue, or that I'm not chaining my virtual types correctly. I am getting the same thing on a number of virtual functions. Below is an example.

    I have
    Qt Code:
    1. class entity_ao {
    2. public:
    3.  
    4. ...
    5.  
    6. virtual void setToZero();
    7.  
    8. ...
    9. }
    10.  
    11. class scalar_ao : public entity_ao {
    12. ...
    13. }
    14.  
    15. class real_ao : public scalar_ao {
    16. public:
    17.  
    18. ...
    19.  
    20. void setToZero() { ... }
    21.  
    22. ...
    23. }
    To copy to clipboard, switch view to plain text mode 

    This compiles just fine, but the .NET 2003 linker says: LNK2001: unresolved external symbol public: virtual void __thiscall entity_ao::setToZero(void)

    I have tried adding virtual void setToZero(); to class scalar_ao, but that changes nothing. I have also tried moving the defn forreal_ao::setToZero from the .h to a .cpp file -- again that changes nothing.

  2. #2
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linker chokes on virtual methods

    Ignore my post on this subject. I just figured out that the base class needs an instantiation of the virtual function. Doing that gets rid of the linker errors.

    K.

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

    Default Re: Linker chokes on virtual methods

    You can also make the method pure virtual in the base class:
    Qt Code:
    1. class entity_ao {
    2. public:
    3.  
    4. ...
    5.  
    6. virtual void setToZero() = 0;
    7.  
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

    The linker won't complain then.
    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. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  2. Getting Linker error on Visual C++
    By samgoud_b in forum Installation and Deployment
    Replies: 7
    Last Post: 28th December 2008, 12:09
  3. QComboBox - Few virtual methods
    By gruszczy in forum Qt Programming
    Replies: 17
    Last Post: 16th July 2008, 16:08
  4. Cost of pure virtual
    By ShaChris23 in forum General Programming
    Replies: 4
    Last Post: 4th November 2007, 18:20

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
  •  
Qt is a trademark of The Qt Company.