以下代码:
std::vector< int > keysDown;
for each ( int currentKey in keysDown )
{
}
正在引发智能感知错误:
1 IntelliSense: a 'for each' statement cannot operate on an expression of type "std::vector<int, std::allocator<int>>"
但它似乎可以编译和运行,有什么想法吗?
似乎没有遍历向量:
void Keyboard::AddKeyToVector( int key )
{
keysDown.push_back( key );
}
void Keyboard::RemoveKeyFromVector( int key )
{
std::vector< int > keysDown; // Placing this here for brevity, it's declared in the class's .h and is instanciated globally
int i;
for( int currentKey : keysDown )
{
if( currentKey == key )
{
keysDown.erase(keysDown.begin()+i);
}
i++;
}
}