mercredi 23 décembre 2020

String vector iterator in c++

I'm just trying to get the iterator over a vector of strings, getting the iterator passed to 'pos' and transfered together with the value at pos to another function, but the compiler tells me there was an invalid conversion at the lambda argument from 'const char*' to 'size_t'. I'm also getting this for header stl_algo.h:

no match for call to '(prototype::Monitor::setOptions(size_t)::<lambda(int)>) (const char&)' __f(__first);

#include <iostream>
#include <Windows.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdio>
.
.
void setOptions(size_t id) {
    switch(id){
        case 0:
            std::for_each(main_menu.lines.begin(), main_menu.lines.end(),[this](size_t pos){
                this->setOption(pos, main_menu.lines[pos]);
            });
            break;
        case 1:
            break;
    }
}

Being all of these inside a class referred by 'this', and setOption is different from setOptions. I've read in other places that it should be fine if it would just convert the iterator for the string pointer to an int, i've also seen examples being used like that.

I also know this whole thing isn't probably the best way to do this, but i've just come to c++ and i'm trying to use some things i learned.

Win10 64bit - gcc (MinGW.org GCC-6.3.0-1)

Aucun commentaire:

Enregistrer un commentaire