Topic: Know your templates well?


Author: "Robert Youdan" <rob@event-horizonsXXNOSPAMXX.com.au>
Date: 1999/09/14
Raw View
This may just be a simple problem of zero sized classes. Check if the
problem goes away when you add some members, for example. My apologies for
not giving you the facts!

Rob

John Smith <jraft@home.com> wrote in message
news:1WvC3.11518$0M6.239532@news1.rdc2.on.home.com...
:
: Does anybody know what the standard says about creating a class local to
: some function and passing it as the argument to a template. Like so:
:
: void SomeFunc()
: {
:      class MyClass
:      {
:      };
:
:      vector<MyClass> Var;
: }
:
: I see no obvious reason why this shouldn't work but my compiler chokes on
: the "Var" definition. The error is very clear: "types with no linkage cannot
: be used as template arguments". My instincts tell me this is a compliancy
: problem but that may be naive. Can anybody point me to the right passage in
: the standard (speculation appreciated but I'd prefer the facts).
:

[ 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: "John Smith" <jraft@home.com>
Date: 1999/09/11
Raw View
Does anybody know what the standard says about creating a class local to
some function and passing it as the argument to a template. Like so:

void SomeFunc()
{
     class MyClass
     {
     };

     vector<MyClass> Var;
}

I see no obvious reason why this shouldn't work but my compiler chokes on
the "Var" definition. The error is very clear: "types with no linkage cannot
be used as template arguments". My instincts tell me this is a compliancy
problem but that may be naive. Can anybody point me to the right passage in
the standard (speculation appreciated but I'd prefer the facts).



[ 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: clamage@eng.sun.com (Steve Clamage)
Date: 1999/09/11
Raw View
"John Smith" <jraft@home.com> writes:


>Does anybody know what the standard says about creating a class local to
>some function and passing it as the argument to a template.

It's not allowed. Section 14.3.1 says:

"A local type, a type with no linkage, an unnamed type or a type
compounded from any of these types shall not be used as a
template-argument for a template type-parameter."

--
Steve Clamage, stephen.clamage@sun.com


[ 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: "John Smith" <jraft@home.com>
Date: 1999/09/12
Raw View
It's not allowed. Section 14.3.1 says:
>
> "A local type, a type with no linkage, an unnamed type or a type
> compounded from any of these types shall not be used as a
> template-argument for a template type-parameter."

Your right. Someone else forwarded an alternate passage though. See 3.5.8.
Too bad. It's extremely useful sometimes to define small local function
objects for private use within a single function. Sad but no doubt there's a
good reason for it (you can still do it of course by moving the class
definition out of the function but it's ugly).



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