Is this possible in C++? toString(ClassName* class)

后端 未结 4 668
天涯浪人
天涯浪人 2021-01-26 05:11

I\'d like to use toString with class argument, but for some reason there is an error. The code is:

Animal.h

#include \"Treatment.h\"
#in         


        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 06:03

    // Animal.h
    // #include "Treatment.h"   remove this
    
    class Treatmemt;    // forward declaration
    
    class Animal
    {
        ...
    };
    

    In your version, Treatment.h and Animal.h include each other. You need to resolve this circular dependency using forward declaration. In .cpp files, include all necessary h-files.

提交回复
热议问题