#include port.h
class ref{
port* ref_port;
char* pkt;
void send_to_port(char* pkt){
ref_port->get_from_ref(pkt);
}
void get_from_port(char* port_pkt){
pkt = port_pkt;
}
//Other tasks to process pkt
}
port.h
1 2 3 4 5 6 7 8 9 10 11 12 13
#include ref.h
typedefclass ref
class port{
ref* port_ref;
char* pkt;
void send_to_ref(char* pkt){
port_ref->get_from_port(pkt);
}
void get_from_ref(char* ref_pkt){
pkt = ref_pkt;
}
//Other tasks to process pkt
}
The order of compilation is
port.h -> ref.h -> top.h
This code is compiled and working fine with gcc-3.3.2
When I tried to compile with gcc-4.2.2 I am getting the following error
1 2
port.h:7 error: invalid use of incomplete type 'struct ref'
port.h:2 error: forward declaration of 'struct ref'
please help me in fixing this issue.
I tried to move the typedef statement into the port classbody and tried with only "class ref" inside port class body. The latter is giving error from top.h saying ref and port::ref are of different type.
What is the issue in with the above files and how to fix it?
You have mutual inclusion, there. Either make ref.h include port.h, or vice versa, but not both. Assuming you make ref.h include port.h, forward-declare ref before the definition of port, and move the definition of port::send_to_ref(), which uses a member of ref, to the .cpp. Do the same with any other member function that uses members of ref.