Hi, this is the first time I see something like this. I had this definition of class and I had to finish it
1 2 3 4 5 6 7 8 9 10 11
template<class T>
class Ptr {
T* ptr;
T* array;
int sz;
public:
template<int N>
Ptr(T* p, T(&a)[N]); //bind to array a, sz == N, initial value p
// . . .
};
this part really confuses me
1 2
template<int N>
Ptr(T* p, T(&a)[N]);
Visual studio generated code for definition of this constructor and its like this
I don't understanding the purpose of this class or function but I can try to explain the syntax.
The first template<class T> is for the class template Ptr.
The second template<int N> is for the function template Ptr<T>::Ptr.
I don't think it is possible to explicitly pass template arguments to the constructor but you probably don't need to do that anyway. Just pass the array as argument to the constructor and the template argument N will be deduced automatically.
Cool, tnx you very much! The class is supposed to keep track on what element pointer points to and throw an exception in case it doesn't point to any of this arrays elements anymore and is being dereferenced.