我正在尝试在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 ==========
为什么?
答案 0 :(得分:4)
不应该
features.begin()
是
listOfFeatures.begin()
和
int criterionFunction(int *features)
在main
之前宣布?请注意,没有std::int
。
答案 1 :(得分:1)
features
未在任何地方声明或定义。