C 期望类对象的类型说明符

C++ expected a type specifier for class object

本文关键字:类型 说明符 对象 期望      更新时间:2023-10-16

我正在尝试使用标头文件创建类对象,但是我在主函数中不断获得此错误。

这是标题文件:

助手

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
class helper {
public:
    helper();
    ~helper();
    void setLabel(cv::Mat& im, const std::string label, const cv::Point & or , const cv::Scalar col);
};

这是CPP文件:

助手.cpp

#include "helper.h"
helper::helper() {
}
void helper::setLabel(cv::Mat& im, const std::string label, const cv::Point & or , const cv::Scalar col)
{
    int fontface = cv::FONT_HERSHEY_SIMPLEX;
    double fontScale = 0.4;
    int thickness = 1;
    int baseline = 0;
    cv::Size text = cv::getTextSize(label, fontface, fontScale, thickness, &baseline);
    cv::putText(im, label, or , fontface, fontScale, col, thickness, CV_AA);
}

现在在 main.cpp 我尝试创建一个实例时:

main.cpp

#include "helper.h"
int main(){
    helper* helper = new helper;
}

它显示此错误:

C2061语法错误:标识符'helper'

如何在main中定义此类的实例?我正在Windows X64上使用Visual Studio 2015。

为变量使用其他名称。

helper* obj = new helper;

当您使用变量名与类名称相同时,类名为变量名称。