[ create a new paste ] login | about

Link: http://codepad.org/Ff3QEt2f    [ raw code | output | fork ]

ninwa - C++, pasted on Oct 7:
template <class T>
class List
{
  private:
    List<T>* _next;

    static List<T>* first(List<T>* p = 0){ 
        static List<T> *t = 0; 
        if(!p){ return t; }
        if(!t){ t=p; return 0; } 
        return t;
    }
  
    static List<T>* next(List<T> *n){
        List<T> *p = List<T>::first();
        while(p->_next) p = p->_next;
        p->_next = n;
        return n;
    }

    void init(){
        _next = 0;
        if(!List<T>::first(this)){}
        else{ List<T>::next(this); }
    }
    
  public:
    T v;
    List<T>(){ init(); }
    List<T>(T v){ init(); this->v = v; }

    const List<T> * const GetNext() const { return _next; }  
};

int main()
{
  List<int> foo(1);
  List<int> bar(2);

  cout << foo.v << " " << foo.GetNext()->v;
}


Output:
1
1 2


Create a new paste based on this one


Comments: