I am a student and I am making a static library for arrays in C ++, so I do not need to rewrite the code every time during the lessons.
I'm in my second year in high school, so I'm not an expert. I want my code to be compatible with all types (int, float, ecc.), But I have problems.
Can you see my code?
// slarray.h
// slarray.cpp #include <iostream> #include "slarray.h" unsigned short i; unsigned short j; template <typename Tipo> void Array<Tipo>::inserisci() { for (i = 0; i < *siz; i++) { std::cout << i << ": "; std::cin >> ary[i]; } } template <typename Tipo> void Array<Tipo>::visualizza() { for (i = 0; i < *siz; i++) { std::cout << ary[i] << " "; } } template <typename Tipo> void Array<Tipo>::copia(Tipo* arycpy) { for (i = 0; i < *siz; i++) { *(arycpy + i) = ary[i]; } } template <typename Tipo> Array<Tipo>::Array(short n) { siz = new short; *siz = n; ary = new Tipo[n]; } template <typename Tipo> Array<Tipo>::~Array() { delete[] ary; delete siz; }
The code gives me errors when I try to initialize a class with:
Array <int> vct(5);
Lpped source share