c++ how to include (circular dependency)?

后端 未结 2 1185
悲&欢浪女
悲&欢浪女 2021-01-15 04:07

I have Environment.h file:

#include 
#include \"interfaces.h\"

#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H

class Environment {};
#endif
<         


        
相关标签:
2条回答
  • For circular dependencies one can use Forward declaration(s)

    In Interfaces.h just above interface definition, forward declare Environment as follows:

    class Environment;
    

    Then when you implement IMoving in a class, you will include Environment.h in its implementation file.

    You can read more about Forward declaration here.

    0 讨论(0)
  • 2021-01-15 05:00

    It looks like you misspelled the class name a few times (Environtment,Envrirontment). Could that be the origin of your issue?

    Otherwise I typically use the Forwarded Declaration

    0 讨论(0)
提交回复
热议问题