Visual C ++ - 构建问题

时间:2012-06-26 11:17:09

标签: c++ visual-c++

我正在尝试在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 ==========

为什么?

2 个答案:

答案 0 :(得分:4)

不应该

features.begin()

listOfFeatures.begin()

int criterionFunction(int *features)

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

答案 1 :(得分:1)

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