#include<stdio.h>
#include "Abc.h"
CAbc *a;//CAbc is a class present in Abc.h
int main(int argc,char **argv)
{
int i=10;hod
float j=15.5;
bool x;
x=a->method(i,j);//method is a member function of CAbc
if(x)
{
printf("Working Correctly");
}
else
{
printf("Not Working");
}
}
If i compile this using
g++ -I/path/to/include code.cpp
I get the Error
/tmp/cc5JgLfF.o: In function `main':
code.cpp:(.text+0x3d): undefined reference to `CAbc::method(int,float)'
collect2: ld returned 1 exit status
Please can anyone tell me am i doing it correctly or not?
It's hard to tell for sure without seeing Abc.h, but from the error message it appears the compiler agrees that method is a member function of class CAbc but couldn't find the actual implementation of the function.
Check to make sure you don't have a spelling error in the name of the function or a different parameter list. Also, make sure you didn't forget the class name in front of the scope resolution operator when you implemented the function. That is, it should be
bool CAbc::method(int,float) not bool method(int,float)
That is an easy mistake to make and will cause the compiler to treat it as a global function instead of the member function you want.