19

I have this error:

"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"

with this code example :

//A.h    
#include "B.h"
class A{
    B* b;
    ..
};

//B.h
#include "A.h"
class B{ 
    A* a; // error error C4430: missing type specifier - int assumed.
};
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
user3571201
  • 203
  • 1
  • 2
  • 6

1 Answers1

31

This is a circular dependency issue. For declaring a pointer to some class, the definition of the class is not needed; i.e. the type doesn't have to be a complete type. So you don't need to include A.h in B.h, forward declaration is enough. Such as:

//B.h
class A; // change the include of A.h to forward declaration
class B { 
    A* a;
};
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • but i need to use the functions of class A in class B! and in your state i can't do this ! – user3571201 Apr 25 '14 at 02:28
  • 3
    @user: You can, just not in the header. In the implementation file of B, (the .cpp), you can include both headers, at which point you can access all the methods and members in A. – Cameron Apr 25 '14 at 02:30
  • @user3571201 You use the functions of class `A` at class `B`'s member functions? If so, you can define the `B`'s member functions in `B.cpp`, in which include the `A.h`. – songyuanyao Apr 25 '14 at 02:30