Calling member functions of a included header file

Hi,
I am new to the forum i wanted to call a member function of an included header file..Here is code i have written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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?
On line 8 is hod a typo?

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.
I suppose that you define the methods in Abc.cpp
1
2
g++ -c code.cpp Abc.cpp #compiling
g++ code.o Abc.o -o code.bin #linking 
Consider yourself lucky if your program crash
1
2
CAbc *a;
a->method(i,j);
Topic archived. No new replies allowed.