c++ header files including each other mutually

后端 未结 6 1465
失恋的感觉
失恋的感觉 2020-12-07 17:29

I have two classes both defined in separate header files. Each file has a field that is type of other class. Now I included in header of each file the header of other file,

6条回答
  •  天涯浪人
    2020-12-07 18:15

    Besides the possibility of forward declaration - if it seems that you need two classes mutually within the other it is out of my experience a sign for a mistake in the depth of inheritance. Eather the classes are a kind of siblings and you should create a parent class for both. Or you are trying to use a class that is in fact a parent class within one that should have a sibling from this parent class. Then you should create this sibling as a third class.

提交回复
热议问题