I have a little problem and I'm working on it for several hours but can't find a solution. Hope you will help me.
Here is my class:
#include <iostream>
#include <iterator>
template <typename T> class Array{
private:
size_t size;
T *newArray;
public:
class Iterator:public std::iterator<std::output_iterator_tag, T>{
T *p;
public:
Iterator(T*x):p(x){}
T& operator*() {return *p;}
};
Array (size_t size = 10): size(size), newArray(new T[size]){};
Iterator begin(){return (Iterator(newArray));}
T printBegin(typename Array<T>::Iterator it){ return *it;}
template <typename E>
T printBegin(typename Array<E>::Iterator it){ return (T)*it;}
};
And here is Main:
using namespace std;
int main(){
Array<int> x;
Array<int> y;
cout << y.printBegin(x.begin()); // prints 0 OK
Array<double> p;
// cout << p.printBegin(x.begin());
return 0;
}
The first cout
works fine but the line that is commented gives this : error: no matching function for call to ‘Array<double>::printBegin(Array<int>::Iterator)’
I don't understand because the last line in my Array class matches (normally) for this function call