Results 1 to 3 of 3

Thread: pointer to members

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default pointer to members

    hi, I've this simple problem with "thinking in c++" page 476; the examples seems wrong or not completely and compiler gets an errror:
    Qt Code:
    1. class HowMany2 {
    2. std::string name;
    3. public:
    4. std::string getName() const ;
    5. };
    6. //main.cpp
    7. std::string (HowMany2::*fp)() const = &HowMany2::getName(); //compiler require a static method
    8. int main() {
    9. fp = &HowMany2::getName();
    10. }
    To copy to clipboard, switch view to plain text mode 
    What's wrong?
    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pointer to members

    It should be:
    Qt Code:
    1. class HowMany2 {
    2. int val;
    3. public:
    4. int getVal() const {
    5. return val;
    6. }
    7. };
    8. //main.cpp
    9. int (HowMany2::*fp)() const = &HowMany2::getVal;
    To copy to clipboard, switch view to plain text mode 


    Are you sure that's the example from the book?

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: pointer to members

    yes it's the same but I changed the variabiles names;
    Now it works: it was the "()" at the end of getName(); (I'm sorry)

    thanks.
    Regards

Similar Threads

  1. Delete auto pointer from QMultiMap
    By phillip_Qt in forum Qt Programming
    Replies: 5
    Last Post: 3rd December 2007, 17:29
  2. Passing a pointer in Signal/Slot Connection
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 6th November 2007, 19:04
  3. Pointer to ActiveX object in QT
    By json84 in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2007, 12:42
  4. QDataStream, QTreeWidgetItem, pointer
    By baca in forum Qt Programming
    Replies: 6
    Last Post: 16th February 2007, 16:59
  5. Pointer to a 2D array of pointers ??
    By aamer4yu in forum General Programming
    Replies: 2
    Last Post: 1st February 2007, 11:16

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.