Q:

does not name a type

Possible Duplicate:
Resolve circular dependencies in c++
What is forward declaration in c++? 

I have two classes A and B. I need to have a field in each which is a pointer to an object of the other class. I get "does not name a type" since the definition of the class is yet to appear. For example:
class A{
   B* b;
}
class B{
   A* a;
}

gets me "B "does not name a type" at the second line.

A:

Use forward declarations:
class B;

class A {
  B* b;
};

class B {
  A* a;
};

This way you're telling the compiler that B is going to be declared later on and that it should not worry. See this for more info: Forward declaration 

