TITLE: local types disallowed as template arguments

(Newsgroups: comp.std.c++, 28 June 99)


STRIEGNITZ: j.striegnitz <J.Striegnitz@fz-juelich.de>

>I am using KAI C++ 3.3e. Compiling the program given below leads to the
>error "a template argument may not reference a local type".
>The message itself is clear, since C IS local to foo - but: 
>
>Why isn't it allowed to do so ? 
>What kind of trouble may occur ?
>
>--------------------------------
>
>template <class T>
>class A
>{
>};
>
>template <class T>
>class B
>{
>  typedef A<B<T> > BinA;  // Works fine
>};
>
>template <class T>
>void foo(T a)
>{
>  class C
>  {
>     typedef A<C> CinA; // Error:
>  };                   // a template argument may not reference a local
>type
>};
>

NARAN: Siemel Naran <sbnaran@localhost.localdomain>

Local classes have internal linkage, which means that only the local
function may access the class.  But the template function or template
class that uses the local class may be instantiated at link time.
But how is the linker to see the local class?  It can't, and so local
classes can't be used as template arguments of functions and classes.
