Local structs as template parameters

M

Marcin Kalicinski

Hi,

Why local structs/classes cannot be used as template parameters?

void f(std::list &l)
{
struct Cmp { /*...*/ };
l.sort(Cmp()); // Error here
}

Best regards,
Marcin
 
V

Victor Bazarov

Marcin said:
Why local structs/classes cannot be used as template parameters?

In comp.lang.c++ the answer is "because the Standard says so".

If you need to know the rationale behind the decision not to allow
local classes in templates, then you should as in comp.std.c++.

IIRC, the reason is that local classes don't have linkage. I do
not remember anything useful beyond that.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top