【发布时间】:2019-06-26 21:32:50
【问题描述】:
我正在尝试使用头文件创建一个类对象,但我在主函数中不断收到此错误。
这是头文件:
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。
【问题讨论】:
-
为变量使用不同的名称:
helper *h = new helper(); -
在标题中避免
using namespace。尤其是当您实际上完全限定类型时。
标签: c++ class object constructor