0

I have a linked List

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;
}

**Please note:above code might not compile as I got it by modifing my original code, which is much much longer. Anyway, since I just need an indication of how to proceed, that shoud be ok.

I want to overload operator>> in a way that in my code I can write something like

#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;
}

However, how do I implement the >> operator, so that I make it indipendent from stream type (file, keyboard)?

I have not been able to find anything about this on google.

geraldCelente
  • 1,005
  • 2
  • 16
  • 36

1 Answers1

0

C++ input streams shares a common base istream, so if you overload the operator>> in terms of istream, that implementation is valid for every type of input stream.

Checkout this answer for a similar question. Its full explained.

Community
  • 1
  • 1
Manu343726
  • 13,969
  • 4
  • 40
  • 75