The class template references the problem (error: The type specifier is missing-assumed to be int). Note: C + + does not support the default int)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.