Topic: Template argument may not reference a local type - WHY ?
Author: "j.striegnitz" <J.Striegnitz@fz-juelich.de>
Date: 1999/06/28 Raw View
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
};
--
==========================================================================
Dipl.-Inform. Joerg Striegnitz
Research Center Juelich
Central Institute for Appied Mathematics (ZAM)
D-52425 Juelich / Germany
eMail.: J.Striegnitz@fz-juelich.de
==========================================================================
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1999/06/28 Raw View
On 28 Jun 99 17:44:15 GMT, j.striegnitz <J.Striegnitz@fz-juelich.de> wrote:
>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 ?
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.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]