I'm trying to create an template of an array class that encapsulates an array of a given type with several methods that are useful but nonstandard to regular c++ arrays. I have created a link struct to contain elements of the array and pointers to both the next and previous elements, and I am trying to overload the << operator to allow the value of a link to be printed easily simply by writing "cout << link_var" but I am having problems. Here is my code
#if !defined _LINK_
#define _LINK_
#if !defined _IOSTREAM_
#include _IOSTREAM_
#endif
typedef unsigned short int size_l;
template <typename T>
class list;
template <typename T>
class link
{
typedef link<T>* link_p;
T value;
link_p next, previous;
public:
link()
: value(NULL), next(NULL), previous(NULL)
{}
link( T _value, link_p _next= NULL, link_p _previous= NULL )
: value(_value), next(_next), previous(_previous)
{}
T rvalue() { return this->value; }
link_p rnext() { return this->next; }
link_p rprevious() { return this->previous; }
const char* type() { return typeid(T).name(); };
friend class list<T>;
template <typename CharT>
friend std::basic_ostream<CharT> &operator<< ( std::basic_ostream<CharT> &out, const link &_link )
{
out << _link.rvalue();
return out;
}
};
#endif /* _LINK_ */
Also, a little side not, I'm not sure if the type() method is the proper return type, code, etc. I would appreciate any help that can be offered, thank you.