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



    std::vector<int> biggest;

std::vector<int>vector1;
std::vector<int>vector2;


int main(){
biggest = [vector2[0],0]; //wrong initialization
for (int apply = 0; apply < (vector2.size()); apply++) {
    if (biggest[0] < vector2[apply + 1]) {
        biggest[0] = vector2[apply + 1];
        biggest[1] = apply + 1;
    }

}

Error C2065 'apply': undeclared identifier.why this error is occurring as i have already defined apply variable in for loop. error should be in initialization of biggest(vector).why wrong compiler code? even intellisense is not giving me error is it a visual studio bug?

1 Answers1

1

apply is in scope in the for loop body, so be assured, the error is not there. But you are aware that apply is out of scope after the loop body?

I'm only answering this because your use of

vector2.size() - 1

will give you hell if vector2 is empty, as the above will wrap around to a large unsigned value and your program will fail spectacularly! Use

for (int apply=0; apply + 1 < vector2.size(); apply++) {

instead.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483