I
imutate
How do I implement << ala std::cout for vector template ?
I already have the following:
#include <vector>
template < typename T >
class Vec : public std::vector< T > {
public:
Vec() { }
Vec( int s ) : std::vector<T>(s) { }
T& operator[](int i) { return this -> at(i); }
const T& operator[](int i) const { return this -> at(i); }
};
I want to output at(i) in the above
T& operator[](int i) {
std::cout << "[" << i << "]=" << this -> at(i) << std::endl;
return this -> at(i); }
But the compiler does not like this -> at(i).
I already have the following:
#include <vector>
template < typename T >
class Vec : public std::vector< T > {
public:
Vec() { }
Vec( int s ) : std::vector<T>(s) { }
T& operator[](int i) { return this -> at(i); }
const T& operator[](int i) const { return this -> at(i); }
};
I want to output at(i) in the above
T& operator[](int i) {
std::cout << "[" << i << "]=" << this -> at(i) << std::endl;
return this -> at(i); }
But the compiler does not like this -> at(i).