我在一个类中创建了一个方法,该方法返回一个 opencv 项目中的一个 vector 。类cpp和头代码:
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 文件中的主函数中,我包含“Detection.h”,创建一个检测对象和一个 Rect vector ,当我尝试分配它们时出现错误
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> >)" (?detection@Detection@@QAE?AV?$vector@V?$Rect_@H@cv@@V?$allocator@V?$Rect_@H@cv@@@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@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"));
我的代码中缺少什么???
最佳答案
你的意思是实现成员方法:
vector<Rect> Detection::detection(string fileName)
{
//...
}
代替自由函数
vector<Rect> detection(string fileName)
?
请注意,如果您到达链接阶段而没有任何编译器错误,则意味着 detection
可能被标记为 static
甚至是一个自由函数,因为它没有似乎与单个 Detection
对象直接相关。
此外,考虑通过 const
引用传递 fileName
。
关于c++ - 错误 LNK2019 : when trying to return a vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20491797/