返回c++中无法识别的类类型

Return class type not recognized in c++

本文关键字:类型 识别 c++ 返回      更新时间:2023-10-16

我写了一个类:

CVerifObj.hpp :

#pragma once
#include <vector>
class VerifObj
{
private:
    cv::Mat m_image;
    PointVector m_plateContour;
    std::string m_imageName;
public:
    VerifObj(const fs::path& imgNameIn);
    ~VerifObj();
    cv::Mat getImage() const;
    std::string getImageName() const;
    PointVector getPlateContour() const;
};
typedef std::vector< VerifObj > VerifObjVector;

具有实现,并且用作另一个类中包含其头文件的另一个函数的类型:

MyCls.hpp :

#pragma once
#include "CVerifObj.hpp"
class MyCls
{
public:
    MyCls();
    ~MyCls();
    static VerifObjVector foo(); // error is here
};

我得到的问题是它不被识别:

/home/sop/proj/CMyCls.hpp:52:2: error: ‘VerifObjVector’ does not name a type

我已经在CMake文件中添加了它。为什么会发生这种情况?

您还没有包含std::vector定义:

#include <vector>

您可能直接或间接地将MyCls.hpp包含在CVerifObj.hpp中,这导致循环包含。这可能会导致问题(未定义的类型)。