vendredi 2 février 2018

How can a function parameter of const_iterator receive iterator as argument?

Please forgive me if this is a basic question or a wrong practice. I have the following code:

void print(std::vector<int>::const_iterator it) {
    std::cout << *it << std::endl;
}

int main() {
    std::vector<int> vec = {3, 4, 5};
    std::vector<int>::iterator it = vec.begin();
    print(it);
}

My question is: The function parameter of print function is const_iterator, but when i am invoking it in the main function i am send iterator. Is there a promotion of iterator to const_iterator? Or what is exactly happening here? I am using C++11

Aucun commentaire:

Enregistrer un commentaire