C++: Has Not Been Declared

后端 未结 2 1685
余生分开走
余生分开走 2020-12-10 19:42

I have seen this type of error everywhere and, although I have looked at the answers, none seem to help.

I get the following error with the following piece of code:<

2条回答
  •  青春惊慌失措
    2020-12-10 20:34

    If you have two headers including each other you end up with a circular dependency, and due to the way the preprocessor works it means one will be defined before the other.

    To fix, I would avoid including A.h in B.h, and just forward declare instead:

    class A;
    class B{
        public:
             static bool doX(A *a);
    };
    

    You can then include A.h in B.cpp

提交回复
热议问题