#include <iostream>
class List
{
List *nextnode;
int val;
int del;
public:
List () : nextnode ( NULL ), val ( 0 ), del ( 0 ) {}
List ( int v ) : nextnode ( NULL ), val ( v ), del ( 0 ) {}
~List ();
List* operator >> ( List* o );
List* operator >> ( int v );
List* operator = ( int v );
operator int ();
int value () const;
List* next () const;
};
int main ()
{
List obj = 1;
obj >> 2;
obj >> 3;
for ( List *p = &obj; p; p = p->next() ) {
std::cout << (int)*p << std::endl;
}
return 0;
}
List::~List ()
{
if ( del ) {
delete nextnode;
}
}
List* List::operator >> ( List* o )
{
if ( nextnode ) {
nextnode->operator >>( o );
} else {
nextnode = o;
}
return this;
}
List* List::operator >> ( int v )
{
List *tmp = new List( v );
tmp->del = 1;
this->operator >> ( tmp );
return this;
}
List* List::operator = ( int v )
{
val = v;
return this;
}
List::operator int ()
{
return val;
}
int List::value () const
{
return val;
}
List* List::next () const
{
return nextnode;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgTGlzdAp7CglMaXN0ICpuZXh0bm9kZTsKCWludCB2YWw7CglpbnQgZGVsOwoJCnB1YmxpYzogCglMaXN0ICgpIDogbmV4dG5vZGUgKCBOVUxMICksIHZhbCAoIDAgKSwgZGVsICggMCApIHt9CglMaXN0ICggaW50IHYgKSA6IG5leHRub2RlICggTlVMTCApLCB2YWwgKCB2ICksIGRlbCAoIDAgKSB7fQoJfkxpc3QgKCk7CglMaXN0KiBvcGVyYXRvciA+PiAoIExpc3QqIG8gKTsKCUxpc3QqIG9wZXJhdG9yID4+ICggaW50IHYgKTsKCUxpc3QqIG9wZXJhdG9yID0gKCBpbnQgdiApOwoJb3BlcmF0b3IgaW50ICgpOwoJaW50IHZhbHVlICgpIGNvbnN0OwoJTGlzdCogbmV4dCAoKSBjb25zdDsKfTsKCmludCBtYWluICgpCnsKCUxpc3Qgb2JqID0gMTsKCQoJb2JqID4+IDI7CglvYmogPj4gMzsKCQoJZm9yICggTGlzdCAqcCA9ICZvYmo7IHA7IHAgPSBwL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