Nov 12, 2011 at 8:41am UTC
Hi all
I need some help in passing a vector into the function arguments.
I am pasting the code and the error message that i am getting form the g++ compiler, please help me out in removing this error.
//function declaration
void pose_to_com(std::vector<float>*,std::vector<float>*,std::vector<float>* );
//function call
vector<float> xcom;
vector<float> ycom;
vector<float> anglecom;
pose_to_com(&xcom,&ycom,&anglecom);
//function definition
undefined reference to
void pose_to_com(std::vector<long> *x_com,std::vector<long> *y_com, std::vector<long> *angle_com)
{
// acces data of vector by pointer ->
// std::vector<float> x_com;
//std::vector<float> y_com;
//std::vector<float> angle_com;
struct odometry{
float x;
float y;
float angle;
};
odometry odometry_old;
odometry_old.x=1;
odometry_old.y=1;
odometry_old.angle=1;
float pi=3.142;
float x_min=odometry_old.x-0.125;
float x_max=odometry_old.x+-0.125;
float y_min=odometry_old.y-0.125;
float y_max=odometry_old.y+0.125;
float angle_min=odometry_old.angle-(5*pi/180);
float angle_max=odometry_old.angle+(5*pi/180);
int ii=0,jj=0,kk=0; float i=0,j=0,k=0;
for ( i=x_min;i<odometry_old.x+0.25;i=i+0.1){
for( j=y_min;j<odometry_old.y+0.25;j=j+0.1){
for( k=angle_min;k<odometry_old.angle+(10*pi/180);k=k+0.5*pi/8);{
//pose_to_compute[ii*jj+jj*kk+kk]=
int a=(ii*jj)+(jj*kk)+k;
x_com[a]=i;
y_com[a]=j;
angle_com[a]=k;
kk=kk+1;
}
jj=jj+1;
}
ii=ii+1;
}
}
I am getting this error from the compiler
g++ -c -Wall icp.cpp -o icp.o
icp.cpp: In function ‘void pose_to_com(std::vector<long int, std::allocator<long int> >*, std::vector<long int, std::allocator<long int> >*, std::vector<long int, std::allocator<long int> >*)’:
icp.cpp:242: error: no match for ‘operator=’ in ‘*(x_com + ((unsigned int)(((unsigned int)a) * 12u))) = i’
/usr/include/c++/4.4/bits/vector.tcc:156: note: candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long int, _Alloc = std::allocator<long int>]
icp.cpp:243: error: no match for ‘operator=’ in ‘*(y_com + ((unsigned int)(((unsigned int)a) * 12u))) = j’
/usr/include/c++/4.4/bits/vector.tcc:156: note: candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long int, _Alloc = std::allocator<long int>]
icp.cpp:244: error: no match for ‘operator=’ in ‘*(angle_com + ((unsigned int)(((unsigned int)a) * 12u))) = k’
/usr/include/c++/4.4/bits/vector.tcc:156: note: candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long int, _Alloc = std::allocator<long int>]
icp.cpp:227: warning: unused variable ‘x_max’
icp.cpp:229: warning: unused variable ‘y_max’
icp.cpp:231: warning: unused variable ‘angle_max’
make: *** [icp.o] Error 1
Nov 12, 2011 at 10:10am UTC
I tried function as you say by passing it as reference instead of pointer, it compiled without error but with this message ,
icp.cpp: In function ‘void pose_to_com(std::vector<float, std::allocator<float> >&, std::vector<float, std::allocator<float> >&, std::vector<float, std::allocator<float> >&)’:
icp.cpp:232: warning: unused variable ‘x_max’
icp.cpp:234: warning: unused variable ‘y_max’
icp.cpp:236: warning: unused variable ‘angle_max’
while executing the program it says
Segmentation fault
I modified the code as under, previously there was a typo my variable type is float not long
void pose_to_com(std::vector<float> &x_com, std::vector<float> &y_com, std::vector<float> &angle_com); //declaration
pose_to_com(xcom,ycom,anglecom); //call
void pose_to_com(std::vector<float> &x_com,std::vector<float> &y_com, std::vector<float> &angle_com) //definition