I wondered if anyone could offer suggestions, without restructuring, on ways to get around this situation: I have a header which contains a class declaration and declares a number of classes that it uses by reference / pointer which is clearly good practice compared to simply including the headers for those classes.
struct Foo;
struct Bar;
struct MyStruct
{
void doIt( const Foo* foo );
void doIt( const Bar* bar );
};
However, while in the example above Foo is a class, Bar is actually a typedef of a class as per the crude example below:
#include <fd_ex.h>
struct Foo
{
int a;
};
struct Bar_
{
int a;
};
typedef Bar_ Bar;
This causes some problems as predeclaring struct Bar is obviously not correct – Bar is not a struct:
"fd_ex.cpp", line 13: Error: Multiple declaration for Bar.
"fd_ex.cpp", line 19: Error: The name Bar is ambiguous, Bar and Bar.
2 Error(s) detected.
I don’t want to expose Bar_ if possible, mainly because in real life this could be very much more complicated than this example.
However, if I have no control over the struct declaration and typedef for Bar, are there any techniques I can use in the header for MyStruct to keep with the spirit of pre-declaring Bar?
you can forward declare the struct itself: