Topic: Are templates in local classes allowed?


Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/10/15
Raw View
Is the following code legal C++?

void foo()
{
  struct S
  {
    template<class T> void foo(T t) {}
  };
  // ...
}

If not, why not?
---
[ 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: Biju Thomas <b_thomas@ibm.net>
Date: 1999/10/15
Raw View
Christopher Eltschka wrote:
>
> Is the following code legal C++?
>
> void foo()
> {
>   struct S
>   {
>     template<class T> void foo(T t) {}
>   };
>   // ...
> }

It is right there in 14.5.2 para 2, saying "A local class shall not have
member templates".

>
> If not, why not?

I will leave it for experts. I don't find it much useful since the local
class can't be used outside the local scope. May be it has something to
do with the inability to provide support for 'exported' templates with
them.

Speaking of which, I find curious that many language designers have
taken a 'socialist' approach to many issues. Like, "if we can't give it
to everyone, we are not going to give it to anyone".

--
Biju Thomas


[ 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: Gene Bushuyev <gbush@synopsys.com>
Date: 1999/10/15
Raw View
Christopher Eltschka wrote:
>
> Is the following code legal C++?
[snip]
No, the code is not legal. 14.5.2p2 explicitly states that "a local
class shall not have member templates."

--
Gene Bushuyev


[ 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              ]