我希望我的getFeatures函数返回结构的向量。我在头文件中声明的结构,但在我的.cpp文件中,我尝试编写我的函数名称,我得到了使用未声明的标识符错误。标识符已声明,我可以在其他函数中使用它。另外,当我编写return语句时,我得到了一个没有可行的vector类型转换为int error。在我的头文件中,我有函数原型,它声明我的函数应该返回我的struct类型的向量,而不是int类型。到底是怎么回事?
#include "Feature_Builder.h"
Feature_Builder::Feature_Builder()
{
int input;
vector<int> intImageVals, temp;
fstream file;
file.open("Integral_Images.txt", ios::in);
if (file.fail())
{
cerr << "File not open!\n";
exit(EXIT_FAILURE);
}
for (int i=0; i<12876; i++)
{
file >> input;
while (input != -1)
{
intImageVals.push_back(input);
file >> input;
}
buildFeatureOne(intImageVals);
buildFeatureTwo(intImageVals);
buildFeatureThree(intImageVals);
buildFeatureFour(intImageVals);
featureIndex = 0;
intImageVals.clear();
}
}
/*****************************************************************************
This is the function with errors! XCode says featureValues is an undeclared
identifier and that features should be of type int!
*****************************************************************************/
vector<featureValues> Feature_Builder::getFeatures()
{
return features;
}
我的头文件
#ifndef Facial_Learner_Feature_Builder_h
#define Facial_Learner_Feature_Builder_h
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Feature_Builder
{
private:
void buildFeatureOne(vector<int>);
void buildFeatureTwo(vector<int>);
void buildFeatureThree(vector<int>);
void buildFeatureFour(vector<int>);
struct featureValues
{
private:
vector<int> vals;
public:
inline void pushValue(int value)
{vals.push_back(value);}
inline int getValue(int i)
{return vals[i];}
};
int featureIndex;
vector<featureValues> features;
public:
Feature_Builder();
vector<featureValues> getFeatures();
};
#endif
答案 0 :(得分:2)
您需要正确的内部结构范围:
vector<Feature_Builder::featureValues> Feature_Builder::getFeatures() { ... }