lundi 29 février 2016

C++ void method getting an error for being void

I am writing a C++ program that will take 2 lists, L and P, and am trying to write a method that will print the elements in L that are in positions specified in P. Here is the code:

#include <iostream>
#include <list>
#include <iterator>
#include <stdlib.h>
using namespace std;

void printLots( list L, list P );

int main()
{
  list< int > numList = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
  list< int > indexList = {2, 4, 6, 8, 10};

  printLots( numList, indexList );

  return 0;
}

void printLots( list L, list P )
{
  int count;
  list::iterator itrIndex;
  list::iterator itrValue;

  for( itrIndex = P.begin(); itrIndex != P.end(); ++itrIndex )
  {
    count = 1;
    for( itrValue = L.begin(); itrValue != L.end(); ++itrValue )
    {
      if( count == *itrIndex )
      {
    cout << "Value in list L at index " << *itrIndex << " = " << *itrValue << endl;
      }
      ++count;
    }
  }
}

For some reason when I try to compile, I am getting an error saying: "error: variable or field 'printLots' declared void void printLots( list L, list P ) I mean, yes the function is void but thats because it is supposed to be. This function doesn't return anything so I have no clue why its giving me an error for this function being void. I have no clue how to fix this. Any help?

Aucun commentaire:

Enregistrer un commentaire