Let's suppose I want to declare structs A and B
struct A{
B toB(){
return B();
}
};
struct B{
A toA(){
return A();
}
};
I'll get an error that type B is undefined
main.cpp:2:2: error: unknown type name 'B'
What is the correct way to forward-declare B?
Doing the following
struct B;
struct A{
B toB(){
return B();
}
};
struct B{
A toA(){
return A();
}
};
results in
main.cpp:4:4: error: incomplete result type 'B' in function definition
main.cpp:1:8: note: forward declaration of 'B'
main.cpp:5:10: error: invalid use of incomplete type 'B'
main.cpp:1:8: note: forward declaration of 'B'