Results 1 to 7 of 7

Thread: weird error

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

    Default weird error

    Hi, I've got this strange error that's only sometimes when I build app; why only sometimes? thanks...
    linking ../bin/person (g++)
    main.o: In function `main':main.cpp.text+0xf2): undefined reference to `Person::setName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    collect2: ld returned 1 exit status
    make[1]: *** [../bin/person] Error 1
    make[1]: Target `first' not remade because of errors.
    make: *** [sub-src] Error 2
    make: Target `first' not remade because of errors.
    *** Exited with status: 2 ***
    Qt Code:
    1. class Person{
    2. private:
    3. string name;
    4. ....................
    5. };
    6. inline void Person::setName(const string n) {
    7. name = n;
    8. }
    9. p.setName("we we we\n");
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 10th November 2006 at 16:26. Reason: changed [code] to [quote]
    Regards

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

    Default Re: weird error

    hi,
    but I cut out keyword 'inline' and it work...but why? Isn't possibile to use 'inline' out a class?? (could be possible microsoft compiler permit it?)
    Regards

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

    Default Re: weird error

    HI guys,
    I read in a book that 'inline function' should be defined in evey file where it's used'; so it's better define it after class declaration:
    Qt Code:
    1. //person.h
    2. class Person{
    3. private:
    4. string name;
    5. public:
    6. Person();
    7. ~Person();
    8. string getName() const {return name;}
    9. inline void setName (const string n);
    10. };
    11.  
    12. inline void Person::setName(const string n) {
    13. this->name = n;
    14. }
    To copy to clipboard, switch view to plain text mode 
    in this way it work! But I remember that my prevoius code work with .net; could anyone confirm that? thanks
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: weird error

    Quote Originally Posted by mickey View Post
    I read in a book
    Excellent, keep it up.

    Quote Originally Posted by mickey View Post
    that 'inline function' should be defined in evey file where it's used'; so it's better define it after class declaration: [...] in this way it work!
    Yes, if you want to use inline function/method in more than one place, you have to put its implementation in a header file.

  5. #5
    Join Date
    Nov 2006
    Location
    Almaty, Kazakhstan
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: weird error

    moreover, when you define a function body in the class declaration as you do with getName(), it automatically becomes inline. so you don't need to use inline keyword, just declare the class as

    Qt Code:
    1. class Person{
    2. private:
    3. string name;
    4.  
    5. public:
    6. Person();
    7. ~Person();
    8.  
    9. string getName() const {return name;}
    10. void setName (const string n) { this->name = n; }
    11. };
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: weird error

    yes I knew that! but then: when must I do use inline keyword if the only use it's mine (but I could define it inside class)?
    Regards

  7. #7
    Join Date
    Nov 2006
    Location
    Almaty, Kazakhstan
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: weird error

    when you declare non-member inline functions, you must use inline keyword.

Similar Threads

  1. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  2. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  3. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11
  4. Fed up with M$ Window$ !!! Why is Tux leaving me alone???
    By fullmetalcoder in forum General Discussion
    Replies: 35
    Last Post: 18th March 2006, 12:57
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.