mardi 31 décembre 2019

why compiler says couldn't deduce template parameter [duplicate]

This question already has an answer here:

#include <iostream>
#include <vector>
#include <list>
using namespace std;

template <typename T>
void print(typename list<T>::iterator first, typename list<T>::iterator end){
    for (; first != end; ++first){
        cout << *first << endl;
    }
}

int main(){
    list <int> list_1 = {0,1,2,3,4,5,6,7,8,9};
    print(list_1.begin(), list_1.end());    
    return 0;
}



void print(typename list<int>::iterator first, typename list<>::iterator end){
    for (; first != end; ++first){
        cout << *first << endl;
    }
}

but when I remove the template parameter, it works. how can I fix the problem to make the template parameter work?

Aucun commentaire:

Enregistrer un commentaire