C ++应该为类对象指定类型说明符

时间:2019-06-26 21:32:50

标签: c++ class object constructor

我试图用头文件创建一个类对象,但是我在主函数中不断遇到此错误。

这是头文件:

helper.h

#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文件:

helper.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。

1 个答案:

答案 0 :(得分:2)

为变量使用其他名称。

helper* obj = new helper;

当使用变量名与类名相同时,类名会被变量名遮盖。