Necesito una mano con una practica que estoy desarrollando. Soy novato y practicamente estoy copiandola pero me da errores. Ayuda por favor.
Vector.h
#ifndef _VECTOR_STATIC_H_
#define _VECTOR_STATIC_H_
#include <iostream>
template<class T, int sz> class Vector {
private:
T aVector [sz];
public:
Vector(void) {}
Vector(const T& val);
inline const int size(void) const {return sz;}
T& operator[] (int i) {return aVector[i];}
};
template<class T, int sz> Vector<T, sz>::Vector(const T& val) {
for(int i = 0; i < sz; i++)
aVector[i] = val;
}
template<class T, int sz> ostream& operator<<(ostream& sout, Vector<T, sz>& v) {
sout << "[ ";
for(int i = 0; i < sz; i++)
sout << v[i] << " ";
sout << "] " << endl;
return sout;
}
template<class T, int sz> istream& operator>>(istream& sin, Vector<T, sz>& v) {
for(int i = 0; i < sz; i++)
sin >> v[i];
return sin;
}
template<class T, int sz> void sort(Vector<T, sz>& v) {
for(int i = 0; i < sz -1; i++)
for(int j= i+1; j < sz; j++)
if (v[i] > v[j]) {
T tmp = v[i];
v[i] = v[j];
v[j] = tmp;
}
}
#endif
Vector.C
#include <iostream>
#include "Vector.h"
using namespace std;
const int Size = 5;
int main (void) {
Vector<int, Size> a;
//Lectura
cout << "Introduce los " << a.size() << "elementos enteros: ";
cin >> a;
Vector<int, Size> b(a);
sort(b);
//Escritura
cout << "Original: " << a;
cout << "Ordenado: " << b;
cout << endl;
}
ERRORES: Salen miles. Esto es el principio
In file included from Vector.C:3:
Vector.h:22: error: expected constructor, destructor, or type conversion before ‘&’ token
Vector.h:30: error: expected constructor, destructor, or type conversion before ‘&’ token
Vector.C: In function ‘int main()’:
Vector.C:14: error: no match for ‘operator>>’ in ‘std::cin >> a’
/usr/include/c++/4.4/istream:119: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]