2013-12-10 30 views
0

我在一個類中創建了一個方法,該方法在opencv項目中返回一個向量。類CPP和報頭碼:錯誤LNK2019:試圖返回一個向量時

Detection::Detection(){} 

vector<Rect> detection(string fileName) 
{ 
    Mat image, gray_image; 
    string path = "C:\\"+ fileName; 
    image = imread(fileName, 1); 

    //create a vector array to store the face found 
    vector<Rect> faces; 

    while(true) 
    { 
    ... 
    } 
    return faces; 
} 

頭文件:

class Detection 
{ 
public: 
    Detection(); 
    vector<Rect> detection(string fileName); 
}; 

在主要的功能是在另一個CPP文件I包括「Detection.h」,創建檢測的一個對象和一個矩形矢量,當我試圖給它們分配我已經得到了錯誤

error LNK2019: unresolved external symbol "public: class std::vector<class cv::Rect_<int>,class std::allocator<class cv::Rect_<int> > > __thiscall Detection::detection(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected][email protected]@[email protected]@@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function _main 

主要功能代碼:

vector<Rect> detections; 
Detection object; 
detections = object.detection("C:\\opencvAssets/BioID_0102.pgm"); 
// ALTERNATIVES 
//object.detection("C:\\opencvAssets/BioID_0102.pgm").swap(detections); 
//detections(object.detection("C:\\opencvAssets/BioID_0102.pgm")); 

我在代碼中缺少什麼?

+0

你可能忘了編譯/鏈接文件與執行 – berak

回答

3

您的意思是實現成員方法:

vector<Rect> Detection::detection(string fileName) 
{ 
    //... 
} 

,而不是自由功能

vector<Rect> detection(string fileName) 

請注意,如果您在沒有任何編譯器錯誤的情況下到達鏈接階段,這意味着detection可能被標記爲static,或者甚至可以是免費函數,因爲它似乎並不直接與單個對象綁定。

此外,請考慮通過fileNameconst參考。

+0

呀!我很傻!不管怎麼說,還是要謝謝你!! –

+0

我幾乎糾正了在我整理OP的代碼縮進問題時,哈哈! :-) –