2

我希望我的 getFeatures 函数返回一个结构向量。我在头文件中声明的结构,但是当在我的 .cpp 文件中我尝试编写我的函数名时,我得到一个使用未声明的标识符错误。标识符已声明,我可以在其他函数中使用它。此外,当我编写返回语句时,我得到向量类型到 int 错误的不可行转换。在我的头文件中,我有函数原型,它指出我的函数应该返回我的结构类型的向量,而不是 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
4

1 回答 1

3

您需要正确的内部结构范围:

vector<Feature_Builder::featureValues> Feature_Builder::getFeatures() { ... }
于 2013-03-23T01:28:12.477 回答