'[Class name]' does not name a type in C++

后端 未结 1 2042
太阳男子
太阳男子 2021-01-06 20:23

I am programming a graph using a list of lists. For that, I have two classes, and each one of this classes has a pointer to another object of the same class and a pointer to

相关标签:
1条回答
  • 2021-01-06 20:58

    The message means that the class name is not in scope. V.h should not include A.cpp, it should include A.h. Same goes for A.h inclusion of V.cpp.

    In general, you never want to #include a CPP file - from a header or from another CPP file. Only .h header files are designed for inclusion by preprocessor.

    In case of circular definitions like this, you should forward-declare the class the pointer to which you are defining, and forego inclusion of that class's header:

    #ifndef VERTICEPUNT_H
    #define VERTICEPUNT_H
    
    class A; // <<== Forward declare the class.
    
    typedef char E;
    
     class V
    {
        public:
        E etiqueta;
        V* siguiente;
        A* primera;
    
        V();
        ~V();
    };
    
    #endif // VERTICEPUNT_H
    
    0 讨论(0)
提交回复
热议问题