Results 1 to 5 of 5

Thread: error:invalid use of member

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default error:invalid use of member

    following errors i am getting on execution. Related part of code i am presenting.

    g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.1.2/include/QtCore -I/usr/local/Trolltech/Qt-4.1.2/include/QtNetwork -I/usr/local/Trolltech/Qt-4.1.2/include/QtGui -I/usr/local/Trolltech/Qt-4.1.2/include -I. -I. -o client.o client.cpp
    client.cpp: In member function ‘void Client::calculating()’:
    client.cpp:112: error: invalid use of member (did you forget the ‘&’ ?)
    client.cpp:113: error: invalid use of member (did you forget the ‘&’ ?)
    client.cpp:125: error: invalid use of member (did you forget the ‘&’ ?)
    client.cpp:128: error: no matching function for call to ‘Client::startSending(<unknown type>, <unknown type>)’
    client.h:53: note: candidates are: void Client::startSending(int, int)
    client.cpp:129: error: invalid use of member (did you forget the ‘&’ ?)
    client.cpp:137: error: invalid use of member (did you forget the ‘&’ ?)
    client.cpp:142: error: invalid use of member (did you forget the ‘&’ ?)
    make: *** [client.o] Error 1
    swap is not a member of class.
    Qt Code:
    1. void swap(int *a,int *b)
    2. {
    3. int *t;
    4. *t = *a;
    5. *a = *b;
    6. *b = *t;
    7.  
    8. }
    9. int x,y,x1=0, y10=0 ,x2=100,y2=100,e,dy,dx,absolute; //declared at global scope, not member of class
    10.  
    11. void Client::calculating()
    12. {
    13.  
    14. if(x1>x2)
    15. {
    16. swap(&x1,&x2);
    17. swap(&y10,&y2);
    18. }
    19. x = x1;
    20. y = y10;
    21.  
    22. if((y2-y10)<0)
    23. absolute = -1;
    24. else
    25. absolute = 1;
    26.  
    27. dy = absolute*(y2-y10);
    28. dx = x2-x1;
    29.  
    30. //usleep(1000*1000*1);
    31. e = (2*dy)-dx;
    32. while( x < x2)
    33. {
    34.  
    35. emit startSending(x,y);
    36. x = x+1;
    37.  
    38. if(e<0)
    39. e = e+(2*dy);
    40.  
    41. else
    42. if (y10>y2)
    43. {
    44. y = y-1;
    45. e = e+(2*dy)-(2*dx);
    46. }
    47. else
    48. {
    49. y = y+1;
    50. e = e+(2*dy)-(2*dx);
    51. }
    52.  
    53.  
    54. }
    55.  
    56.  
    57.  
    58. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 19th June 2006 at 11:17. Reason: changed [ code ] to [ quote ] to allow wrapping of long lines

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error:invalid use of member

    In swap, all references to t should be without the *. E.g. t = *a; *a = *b; *b = t;

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

    Default Re: error:invalid use of member

    Is this Client class a widget?

  4. #4
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: error:invalid use of member

    yes , it inherits QDialog.
    But wheni made these global variables x,x1,y10,y2 etc. a member of client , allthings went well, why i couldn't understand

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

    Default Re: error:invalid use of member

    Quote Originally Posted by quickNitin
    yes , it inherits QDialog.
    But wheni made these global variables x,x1,y10,y2 etc. a member of client , allthings went well, why i couldn't understand
    Because x and y are also names of QDialog methods, so those global variables weren't visible. Usually usage of global variables is a bad idea, but in that case you could access using the scope operator.

    Like this:
    Qt Code:
    1. ::x = 10 + ::y;
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to jacek for this useful post:

    quickNitin (20th June 2006)

Similar Threads

  1. emiting signals from const member functions !?
    By sunil.thaha in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2006, 11:29
  2. Hey :: I am a new Member,
    By :db:sStrong in forum General Discussion
    Replies: 5
    Last Post: 18th February 2006, 20:01
  3. const member definitions in a class ....
    By TheKedge in forum General Programming
    Replies: 5
    Last Post: 15th February 2006, 13:03
  4. Hey everyone - new member
    By CuCullin in forum General Discussion
    Replies: 16
    Last Post: 14th February 2006, 16:59
  5. Replies: 5
    Last Post: 29th January 2006, 17:00

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.