PDA

View Full Version : error:invalid use of member



quickNitin
19th June 2006, 07:53
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.


void swap(int *a,int *b)
{
int *t;
*t = *a;
*a = *b;
*b = *t;

}
int x,y,x1=0, y10=0 ,x2=100,y2=100,e,dy,dx,absolute; //declared at global scope, not member of class

void Client::calculating()
{

if(x1>x2)
{
swap(&x1,&x2);
swap(&y10,&y2);
}
x = x1;
y = y10;

if((y2-y10)<0)
absolute = -1;
else
absolute = 1;

dy = absolute*(y2-y10);
dx = x2-x1;

//usleep(1000*1000*1);
e = (2*dy)-dx;
while( x < x2)
{

emit startSending(x,y);
x = x+1;

if(e<0)
e = e+(2*dy);

else
if (y10>y2)
{
y = y-1;
e = e+(2*dy)-(2*dx);
}
else
{
y = y+1;
e = e+(2*dy)-(2*dx);
}


}



}

e8johan
19th June 2006, 11:12
In swap, all references to t should be without the *. E.g. t = *a; *a = *b; *b = t;

jacek
19th June 2006, 12:18
Is this Client class a widget?

quickNitin
19th June 2006, 13:14
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

jacek
19th June 2006, 16:21
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:
::x = 10 + ::y;