2016-05-12 6 views
1

OpenCVを使用してiOSプロジェクトを作成しています。現在、既存のC++プロジェクトの一部をiOSアプリケーションにインポートしようとしています。最近このエラーが発生しました。私はまだC++と客観的なCの両方には全く新しいので、おそらく私は痛いほど明白な何かを見逃しています。'function'の行外定義が 'Class'の宣言と一致しません

私は、Contour名前空間に新しい関数を定義して実装しようとすると同じエラーが発生し、仮想指定子を追加してもこれを変更していないことに気付きました。しかし、描画機能は問題は発生しません。私も同様の質問で示唆されているようにxcodeを終了して再起動しようとしましたが、問題は解決しません。

関数writeToFile(string fname)は、以下に示すように、ヘッダーファイルで定義されていますが、インプリメンテーションファイルでは、「writeToFile」のアウトラインの定義が'輪郭'」:

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

は、任意の助けいただければ幸いです。

+1

Typo ?? 'String'と' string'です。 –

答えて

4

あなた宣言

void writeToFile(String fname); 

は実装

void Contour::writeToFile(string fname) 

実装は小文字の-sの持っていた資本-S "文字列" 使用宣言と一致しません "の文字列を。"それらを一致させることでそれを修正する必要があります。

+0

それはそうしました。ありがとう、それは私にも起こっていなかったので、そう簡単だったでしょう。 –

関連する問題