0

我正在尝试在以下位置构建这个小程序Visual C++ 2008 Express Edition

    #include "stdafx.h"
    #include <iostream>
    #include <vector>

    int main(){
    std::vector<bool> listOfFeatures(4,false);
    for(std::vector<bool>::iterator i = features.begin(); i != features.end(); i++){
    std::int maxValue = criterionFunction(*listOfFeatures);
    }
    }
    std::int criterionFunction(std::int *features){
    return -2*features[1]*features[2]+3*features[1]+5*features[2]-2*features[1]*features[2]*
    features[3]+7*features[3]+4*features[4]-2*features[1]*features[2]*features[3]*
    features[4];
}

但是,得到以下输出:

1>------ Build started: Project: SFS, Configuration: Debug Win32 ------
1>Compiling...
1>SFS.cpp
1>.\SFS.cpp(7) : error C2065: 'features' : undeclared identifier
1>.\SFS.cpp(7) : error C2228: left of '.begin' must have class/struct/union
1>        type is ''unknown-type''
1>.\SFS.cpp(7) : error C2065: 'features' : undeclared identifier
1>.\SFS.cpp(7) : error C2228: left of '.end' must have class/struct/union
1>        type is ''unknown-type''
1>.\SFS.cpp(8) : error C2589: 'int' : illegal token on right side of '::'
1>.\SFS.cpp(8) : error C2143: syntax error : missing ';' before '::'
1>.\SFS.cpp(11) : error C2589: 'int' : illegal token on right side of '::'
1>.\SFS.cpp(11) : error C2059: syntax error : '::'
1>.\SFS.cpp(11) : error C2589: 'int' : illegal token on right side of '::'
1>.\SFS.cpp(11) : error C2143: syntax error : missing ';' before '{'
1>.\SFS.cpp(11) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Users\Ola\Documents\Visual Studio 2008\Projects\SFS\SFS\Debug\BuildLog.htm"
1>SFS - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这是为什么?

4

2 回答 2

4

不应该

features.begin()

listOfFeatures.begin()

int criterionFunction(int *features)

之前被宣布main?注意没有std::int

于 2012-06-26T11:18:27.203 回答
1

features没有在任何地方声明或定义。

于 2012-06-26T11:19:33.320 回答