[ create a new paste ] login | about

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

ninwa - C++, pasted on Nov 23:
// A once-linked list of nodes of various types.
#include <iostream>
#include <string>
using namespace std;


class genericNode
{
public:
	genericNode *next;
	virtual void print(){}
};

template < class T >
class node : public genericNode
{
public:
	T data;
	void print(){ cout << data << " "; }

	node(){ next = NULL; }
	node(T d) : data(d) { next = NULL; }
};

void print_nodes(genericNode *n)
{
	if( n != NULL )
	{
		n->print();
		while( n->next != NULL )
		{

			n = n->next;
			n->print();
		}
	}
}

int main()
{
	node<int> n(3);
	n.next = new node<string>("Hi");
	n.next->next = new node<bool>(true);
	
	print_nodes(&n);
}


Output:
1
3 Hi true 


Create a new paste based on this one


Comments: