Compiler error C4430: missing type specifier - int assumed

user3571201 picture user3571201 · Apr 25, 2014 · Viewed 80.5k times · Source

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.
};

Answer

songyuanyao picture songyuanyao · Apr 25, 2014

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;
};