简体   繁体   中英

C++ expected a type specifier for class object

I am trying to create a class object with the header file, but I keep getting this error in the main function.

This is the header file:

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);
};

and this is the cpp file:

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);
}

Now in main.cpp when I try to create an instance:

main.cpp

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

It shows this error:

C2061 syntax error: identifier 'helper'

How can I define an instance of this class in main? I am using Visual Studio 2015 on windows x64.

Use a different name for the variable.

helper* obj = new helper;

When you use the variable name to be the same as the class name, the class name is shadowed by the variable name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM