🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by David Cok Thu, 04 Apr 1991 11:45
overloading templates
#1005
Author: David Cok
Date: Thu, 04 Apr 1991 11:45
44 lines
1936 bytes
Will someone privy to the ANSI discussions on templates answer this for me?:

Is it expected that class template definitions will be able to be overloaded
or have default arguments?  The ARM does not discuss this except to say that
"There must be exactly one definition for each template of a given name in a
program", which leads me to think the answer to my question is no.  However,
a template is basically a function which returns a class or a function (it
just has to be evaluated at compile-time), so one might think that it could
be overloaded like ordinary functions.

For example:
	template<class T> class Vector ...
			// defines a template for a Vector of T of arbitrary
			// and variable size
	template<class T, int size> class Vector ...
			// defines a template for a Vector of T of fixed size
			// some checks on sizes of vectors could be done at
			// compile-time

then
	Vector<int> a,b;
	Vector<int,10> c,d;
	Vector<int,20> e,f;

	...
	a+=b; // runtime check that sizes of vectors are the same
	c+=d; // ok, sizes match at compile-time
	c+=e; // compile-time type error -- no operation defined to add a
		// Vector<int,10> to a Vector<int,20>


Another example:

	template<class T,int size=100> class Stack ...
		// defines a Stack implemented on top of a fixed size array
		// with default size of 100

	Stack<int> a; // Stack of ints with size of 100
	Stack<int,200> b; // Stack of ints with size of 200


David R. Cok
Eastman Kodak Company -- Imaging Science Laboratory
cok@Kodak.COM
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads