1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <typeinfo>
#include <iostream>
using namespace std;
template <class T, int N>
class mysequence {
T memblock [N];
public:
mysequence();
template <class U, int M> mysequence(mysequence<U,M>& ms)
{cout << "Typeid is " << typeid(ms).name() << "\n"
<< " M=" << M << " N=" << N;
cout << "Typeid of U is " << typeid(U).name() << "\n";
cout << "Typeid of T is " << typeid(T).name() << "\n";
}
template <class U, int M> mysequence();
void setmember (int x, T value);
T getmember (int x);
};
template <class T, int N>
void mysequence<T,N>::setmember (int x, T value) {
memblock[x]=value;
}
template <class T, int N>
T mysequence<T,N>::getmember (int x) {
return memblock[x];
}
template <class T, int N>
mysequence<T,N>::mysequence()
{
for(int i=0; i<N; i++)
(*this).setmember(i,0);
cout << " N=" << N;
// return (*this);
}
int main () {
const int N = 3;
cout << "The number of elements for the 2 arrays (int, double) is " << N;
mysequence <int,N> myints; //default ctor
mysequence <double,N> myfloats; //default ctor
mysequence<int,4> myints1(myfloats); //to test copy ctor
return 0;
}
|