[ create a new paste ] login | about

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

C++, pasted on Apr 10:
#include <iostream>

template <int N> struct Base
{
	Base(int x) : x(x)
	{
	};

	Base &operator = (const Base &other)
	{
		std::cout << "Base<" << N << ">::operator = (const Base<" << N << "> &)" << std::endl;
		
		x = other.x;
		
		return *this;
	}

	int x;
};

struct Derived : Base<0>, Base<1>, Base<2>
{
	Derived(int x0, int x1, int x2) : Base<0>(x0), Base<1>(x1), Base<2>(x2)
	{
	}
};

int main(void)
{
	Base<0> *b0 = new Base<0>(0);
	Base<1> *b1 = new Base<1>(1);
	Base<2> *b2 = new Base<2>(2);
	
	Derived *d = new Derived(3, 4, 5);
	
	*b0 = *d;
	*b1 = *d;
	*b2 = *d;
	
	std::cout << b0->x << std::endl;
	std::cout << b1->x << std::endl;
	std::cout << b2->x << std::endl;
	
	return 0;
}


Output:
1
2
3
4
5
6
Base<0>::operator = (const Base<0> &)
Base<1>::operator = (const Base<1> &)
Base<2>::operator = (const Base<2> &)
3
4
5


Create a new paste based on this one


Comments: