I have two classes, one and two, each having a friend member function with an pointer to the other. The first header file is as per below:
#ifndef FIRSTCLASS_H
#define FIRSTCLASS_H
class two;
class one {
private:
int one_data;
public:
friend void second_data (two *);
};
#endif
The second header file looks like this:
#ifndef SECONDCLASS_H
#define SECONDCLASS_H
class one;
class two {
private:
int two_data;
public:
friend void first_data (one *);
};
#endif
The actual functions are in a third .cpp file. I wrote the functions with appropriate class qualifier, it gives an compilation error. I am using g++. The functions are as follows:
#include "firstclass.h"
#include "secondclass.h"
void two::first_data (one * class1) {
}
void one::second_data (two * class2) {
}
The errors are as followa:
error:no ‘void two::first_data (one*)’ member function declared in class ‘two’
error: no ‘void one::second_data(two*)’ member function declared in class ‘one’
When I drop the class qualifier before the function name, the code compiles. The modified functions are as follows:
void first_data(one * class1) {
}
void second_data(two * class2) {
}
I am new to c++ and I am not sure if I am doing anything wrong in the first case. Please enlighten me.