Proper way to #include when there is a circular dependency?

后端 未结 5 1064
我寻月下人不归
我寻月下人不归 2020-12-04 02:49

I\'m using #pragma once, not #include guards on all my h files. What do I do if a.h needs to #include b.h and b.h needs to #include a.h?

I\'m getting all sorts if e

5条回答
  •  暖寄归人
    2020-12-04 03:28

    You need to forward declare the definitions you need. So if A uses B as a parameter value, you need to forward declare B, and vice versa.

    It could be that just forward declaring the class names:

     class A;
     class B;
    

    solves your problems.

    The accepted answer to this question provides some additional guidance.

提交回复
热议问题