我有一个链接列表
template<class T>
class Node<T>
{
typedef T elementType;
typedef Node<T>* position;
elementType _element;
position _next;
};
template <class T>
class LinkedList
{
public:
typedef Node<T>::position position;
typedef Node<T>::elementType elementType;
//operatori
bool empty() constprevious;
unsigned int size() constprevious; //convertire il tipo ritornato in unsigned int!! per tutte classi e metodi rilevanti **LEO**
elementType read(const position) constprevious;
void write(const position p, const elementType)previous;
void insert(const elementType)previous;
void insert(const position, const elementType)previous;
void delete(position)previous;
position first() constprevious;
position last() constprevious;
position next(position) constprevious;
position previous(position) constprevious;
void deleteAll();
private:
position _first;
position _last;
int _numElements;
};
template<class T>
istream &operator>> (istream &input, LinkedList<T> &linkedList )
{
//operator Code
return is;
}
**请注意:上面的代码可能无法编译,因为我通过修改我的原始代码得到了它,这要长得多。无论如何,因为我只需要指示如何进行,那应该没问题。
我想重载 operator>> 在我的代码中我可以写类似的东西
#include <cstdlib>
#include <iostream>
using namespace std;
//#include "LinkedList.h"
int main(int argc, char *argv[])
{
LinkedList linkedList;
cin>>linkedList; //<-- operator>> call.
system("PAUSE");
return EXIT_SUCCESS;
}
但是,如何实现 >> 运算符,使其独立于流类型(文件、键盘)?
我无法在谷歌上找到任何关于此的内容。