“不命名类型”错误 C++

“does not name a type” error c++

本文关键字:错误 C++ 不命名类型 类型      更新时间:2023-10-16

我有一个声明如下的类,但我不断收到"段未命名类型"错误。我看过其他类似的问题,但我似乎找不到解决问题的方法。有什么帮助吗?提前感谢!:)

#ifndef ENTRANCE_H
#define ENTRANCE_H
#include "Segment.h"
#include <vector>
#include "Diodio.h"

class Entrance
{
    public:
        Entrance();
        ~Entrance();
        void operate();

    protected:
        Segment *givesEntryTo;
        std::vector<Diodio> elBooths;
            std::vector<Diodio> manBooths;
    private:
};
#endif // ENTRANCE_H

您可以通过使用类的前向声明而不是#include来避免循环包含问题:

#ifndef ENTRANCE_H
#define ENTRANCE_H
#include <vector>
#include "Diodio.h"
class Segment;    
class Entrance
{
    public:
        Entrance();
        ~Entrance();
        void operate();

    protected:
        Segment *givesEntryTo;
        std::vector<Diodio> elBooths;
            std::vector<Diodio> manBooths;
    private:
};
#endif // ENTRANCE_H

(入口.cpp可能需要也可能不需要#include "Segment.H"