Hi guys,

Could you tell me what's wrong with this code? I don't get why the compiler says it can't find a matching function...

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

template <class T>
int printVector(vector<T> &x){
    for(unsigned int col = 0; col < x.size(); col++){
        cout << x[col] << " ";
    }
    cout << endl;

    return 0;
}

int main(){
    vector<int> x;
    x.resize(10, 100);
    printVector(&x);

    return 0;
}

Errors:

C:\Code\TEMP\main.cpp||In function `int main()':|
C:\Code\TEMP\main.cpp|28|error: no matching function for call to `printVector(std::vector<int, std::allocator<int> >*)'|
||=== Build finished: 1 errors, 0 warnings ===|

Recommended Answers

All 2 Replies

Since you have printVector(vector<T> & x) pass by reference ... printVector( x );

Oooooooooh okay, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.