Question: 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`?

Answer: 
I'm not sure if it works exactly the same in C++, but in C, I often declare "opaque" struct, which in header file (let's say `mystruct.h`) has:

```
typedef struct MyStruct_ MyStruct;

// + function prototypes using MyStruct*

```

and then I can use pointer to `MyStruct` without actually knowing what it is, like: `MyStruct *x;` , but not `MyStruct x[3];` (as the compiled does not know the size of MyStruct)

Then in the source file `mystruct.c` I define the `struct MyStruct_`.

So I think you could try to replace:

```
class Bar;

```

with:

```
typedef struct Bar_ Bar;

```

(you could probably just say `typedef Bar_ Bar;` in c++)
This should do the trick:

```
struct Bar_;
typedef Bar_ Bar;

```