Problem Description:
There are now two template classes (header file A.h is 1~14 line, header file B.h is 15~27 line):
///////////////////////////////////////////
File A.h
//
4: #include "B.h"
Template <class t>
class A
8: {
Public:
Ten: T A;
One: B b_ptr;
: A (): A (0), b_ptr (NULL) {}
13:};
///////////////////////////////////////////
File B.h
//
: #include "A.h"
Template <class t>
class B
22: {
Public:
: T B;
: A a_ptr;
+: B (): B (0), b_ptr (NULL) {}
27:};
The compilation here will report the following error:
Error C4430: Missing type descriptor-assumed to be int. Note: C + + does not support the default int
Error C2143: syntax error: Missing "," (in front of "<")
Workaround:
Forward Declaration of Class B in A.h, a forward declaration of Class A in B.h, as shown in the following code (code 7~8 lines and 25~26 lines):
///////////////////////////////////////////
File A.h
//
4: #include "B.h"
Forward statement
Template <class t>
class B
Template <class t>
class A
12: {
Public:
: T A;
: B b_ptr;
: A (): A (0), b_ptr (NULL) {}
17:};
///////////////////////////////////////////
File B.h
//
: #include "A.h"
Forward statement
Template <class t>
class A
Template <class t>
class B
30: {
Public:
C: T B;
: A a_ptr;
: B (): B (0), b_ptr (NULL) {}
35:};
Keywords:
Forward declaration, template class
E-mail:[email protected]
The class template references the problem (error: The type specifier is missing-assumed to be int). Note: C + + does not support the default int)