'function'的外联定义与'Class'中的任何声明都不匹配
out-of-line definition of 'function' does not match any declaration in 'Class'
所以我正在使用OpenCV处理一个iOS项目,目前正试图将现有c++项目的一部分导入到iOS应用程序中,最近出现了这个错误。我对C++和目标C都还很陌生,所以也许我错过了一些显而易见的东西。
我注意到,试图在Contour命名空间中定义和实现任何新函数都会导致同样的错误,添加虚拟说明符似乎不会改变这一点。draw函数没有遇到问题。我也尝试过按照类似问题中的建议退出并重新启动xcode,但问题仍然存在。
函数writeToFile(字符串fname)在头文件中定义,如下所示,但在实现文件中,错误报告"‘writeToFile’的越界定义与‘Contour’中的任何声明都不匹配":
2DContour.h:
#ifndef TWODCONTOUR_H
#define TWODCONTOUR_H
#include <vector>
using std::vector;
#include <opencv2/core.hpp>
using namespace cv;
class Contour
{
protected:
vector<Vec2f> points;
virtual void process(){} // virtual function interface for after-creation/edit processing (eg. refinement/validation)
public:
inline Vec2f at(int index){return points[index];}
inline void clear(){points.clear();}
inline void addPoint(Vec2f p){points.push_back(p);}
inline void finish(){process();}
inline void randomize(int num)
{
num--;
points.clear();
int cycles=6;//rand()%6+1;
float offset=(float)rand()/(float)RAND_MAX*2.0f*3.141592654f;
float noisemag=(float)rand()/(float)RAND_MAX;
for(int i=0;i<num;i++)
{
float a=(float)i/(float)num;
addPoint(
Vec2f(sin(a*2.0f*3.141592654f),cos(a*2.0f*3.141592654f))+
noisemag*Vec2f(sin(cycles*a*2.0f*3.141592654f+offset),cos(cycles*a*2.0f*3.141592654f+offset)));
}
addPoint(points.front());
process();
}
void writeToFile(String fname);
virtual Mat draw(Mat canvas, bool center=false, Scalar colour=Scalar(255,255,255), int thickness=1);
inline int numPoints(){return points.size();}
inline Vec2f getPoint(int i){return points[i];}
};
#endif
2DContour.cpp:
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <fstream>
#include "2DContour.h"
using namespace std;
using namespace cv;
//error occurs here
void Contour::writeToFile(string fname)
{
ofstream out;
out.open(fname.c_str());
for(unsigned int i=0;i<points.size();i++)
out << points[i][0]<<" "<<points[i][1]<<endl;
out.close();
std::cout<<"Wrote: "<<fname<<std::endl;
}
//draw() function does not experience the same error however
Mat Contour::draw(Mat canvas, bool center, Scalar colour, int thickness)
{
Mat r=canvas.clone();
cv::Point c(center?r.cols/2:0,center?r.rows/2:0);
for( unsigned int j = 0; j < points.size(); j++ )
{
line(r,c+ cv::Point(points[j]*50),c+ cv::Point(points[(j+1)%points.size()]*50),colour,thickness, 8 );
}
return r;
}
如有任何帮助,我们将不胜感激。
您的申报
void writeToFile(String fname);
与实现不匹配
void Contour::writeToFile(string fname)
声明使用了大写-S"字符串",而实现使用了小写-S"字符串"。匹配这些应该可以修复它。
相关文章:
- 错误:'EM::EM(...)' 的原型与类 'EM' 中的任何原型都不匹配
- 显式专用化 - 模板 ID 与任何模板声明都不匹配
- 模板类专用化:模板 ID 与任何模板声明都不匹配
- 模板 ID 与任何模板声明都不匹配
- 我的 Boost 正则表达式与任何内容都不匹配
- template-id 与任何模板声明 GNU gcc 编译器都不匹配
- 错误:'void TNode::inititTree(TNode*)' 的原型与类 'TNode' 中的任何原型都不匹配
- Qt:"closeEvent"的外线定义与"MainWindow"中的任何声明都不匹配
- 错误:原型与类中的任何原型都不匹配
- "...."的原型与类中的任何"..."都不匹配
- qregexp不匹配任何东西
- 你能帮助解决这个错误吗?(g++原型与类中的任何原型都不匹配)
- 函数的原型与类C++中的任何原型都不匹配
- 为什么这些函数模板中的任何一个都与实例化不匹配?
- 'function'的外联定义与'Class'中的任何声明都不匹配
- C++,构造函数:'class'的外联定义与'class'中的任何声明都不匹配
- C++11正则表达式不匹配任何内容
- 错误:类的原型与任何类 - 继承都不匹配
- 错误:“XXX”的原型与类“YYY”中的任何原型都不匹配
- 为什么regex_search不匹配任何东西