Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!asuvax!ncar!gatech!udel!rochester!kodak!islsun!cok From: cok@islsun.Kodak.COM (David Cok) Newsgroups: comp.std.c++ Subject: overloading templates Message-ID: <1991Apr4.114557.17897@kodak.kodak.com> Date: 4 Apr 91 11:45:57 GMT Sender: cok@Kodak.COM Organization: Eastman Kodak Co., Rochester, NY Lines: 44 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 Vector ... // defines a template for a Vector of T of arbitrary // and variable size template 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 a,b; Vector c,d; Vector 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 to a Vector Another example: template class Stack ... // defines a Stack implemented on top of a fixed size array // with default size of 100 Stack a; // Stack of ints with size of 100 Stack b; // Stack of ints with size of 200 David R. Cok Eastman Kodak Company -- Imaging Science Laboratory cok@Kodak.COM