Results 1 to 4 of 4

Thread: Why can't I call base public method?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Why can't I call base public method?

    This is weird. Any idea on this error?

    The compiler (g++) complains

    main.cpp: In function `int main()':
    main.cpp:42: error: no matching function for call to `ClassB::zValue(QPointF, bool*)'
    main.cpp:32: note: candidates are: virtual double ClassB::zValue(double, double, bool*) const
    gmake: *** [main.o] Error 1


    Qt Code:
    1. #include <QPointF>
    2.  
    3. class ClassA
    4. {
    5. public:
    6.  
    7. ClassA() {}
    8. virtual ~ClassA() {}
    9.  
    10. virtual double zValue( double xpos, double ypos, bool* ok=0 ) const=0;
    11. double zValue( const QPointF& xy, bool* ok=0 ) const;
    12.  
    13. };
    14.  
    15. double ClassA::zValue( const QPointF& xy, bool* ok ) const
    16. {
    17. return zValue( xy.x(), xy.y(), ok );
    18. }
    19.  
    20. class ClassB : public ClassA
    21. {
    22. public:
    23.  
    24. ClassB() {}
    25. ~ClassB() {}
    26.  
    27. virtual double zValue( double xpos, double ypos, bool* ok=0 ) const;
    28.  
    29. };
    30.  
    31. double ClassB::zValue( double xpos, double ypos, bool* ok ) const
    32. {
    33. if ( ok ) *ok = true;
    34. return xpos + ypos;
    35. }
    36.  
    37. int main()
    38. {
    39. ClassB mess;
    40.  
    41. bool ok;
    42. mess.zValue( QPointF( 0, 0 ), &ok );
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why can't I call base public method?

    the declaration is hidden by the subclass.
    add the line
    Qt Code:
    1. using ClassA::zValue;
    To copy to clipboard, switch view to plain text mode 
    to the subclass ClassB

    HTH

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why can't I call base public method?

    Quote Originally Posted by caduel View Post
    the declaration is hidden by the subclass.
    add the line
    Qt Code:
    1. using ClassA::zValue;
    To copy to clipboard, switch view to plain text mode 
    to the subclass ClassB

    HTH
    Thanks! First time seeing this!

  4. #4
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Why can't I call base public method?

    Quote Originally Posted by caduel View Post
    the declaration is hidden by the subclass.
    add the line
    Qt Code:
    1. using ClassA::zValue;
    To copy to clipboard, switch view to plain text mode 
    to the subclass ClassB

    HTH
    Quote Originally Posted by lni View Post
    Thanks! First time seeing this!
    better just use mess.ClassA::zValue(QPointF(0,0),&ok);

Similar Threads

  1. Replies: 6
    Last Post: 3rd September 2008, 14:27
  2. Replies: 3
    Last Post: 16th May 2007, 11:07
  3. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  4. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 21:26
  5. Static field and public method
    By probine in forum General Programming
    Replies: 1
    Last Post: 5th March 2006, 11:02

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.