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

后端 未结 5 1060
我寻月下人不归
我寻月下人不归 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:42

    The solution for this issue is 'forward declaration'.

    If you have a class or a function that needs to be used in 2 headers one of the headers needs to forward declare the used class or type. Or you need to consider to restructure your headers.

    This is a common beginner issue that circular dependencies are causing such issues. If you google on 'forward declaration' will find tons of results.

    Since your question was too unspecific I can't give you an exact answer, sorry for this.

提交回复
热议问题