Thx to both EVOEx and laserlight give such a good opinion.
Though I am not familiar with generic algorithm.. I'll learn it ASAP.
However,
I tried again as following..
Code:
50 template <class Type>
51 void printResult(const Type& array) {
52
53 typedef typename Type::iterator Iter;
54 //Print contents
55 for (Iter iter1= array.begin(); iter1 != array.end(); ++iter1)
56 cout << *iter1 << " ";
57 cout << endl;
Code:
79 int main(void) {
80 vector<int> numList;
81 int i = 0;
82 do {
83 numList.push_back(i);
84 } while (i++ != 10);
85 printResult(numList);
And it didn't work..
test.cpp: In function ‘void printResult(const Type&) [with Type = std::vector<int, std::allocator<int> >]’:
test.cpp:85: instantiated from here
test.cpp:55: error: conversion from ‘__gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >’ to non-scalar type ‘printResult(const Type&) [with Type = std::vector<int, std::allocator<int> >]::Iter’ requested
Why didn't the compiler instantianted Type = vector<int> as I want?