473,499 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Local structs as template parameters

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
Jul 22 '05 #1
2 1418
Marcin Kalicinski wrote:
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
Jul 22 '05 #2
On Wed, 26 May 2004 13:13:43 +0200, "Marcin Kalicinski"
<ka****@poczta.onet.pl> wrote:
Hi,

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


Because the have internal, not external, linkage, which currently
would cause problems for template instantiation. See
http://www.open-std.org/jtc1/sc22/wg...2003/n1427.pdf

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1764
by: Neelesh Bodas | last post by:
Hello all, Is there a way to pass an object of local type to a template? template <class T> int fun(const T& x) { return 1; } int bar() { enum Color { Red, Green, Blue}; Color c;
61
3687
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
2
1698
by: Martijn van Buul | last post by:
Hi, Today, I stumbled over the following: I had a struct, whose scope only made sense within a single function, and I wanted to use std::swap() on it, like the following example: #include...
28
2527
by: cpluslearn | last post by:
Hi, I have a local class inside a function template. I am able to wrap any type in my local class. Is it legal C++? What type of class is Local? Is it a class template or regular class? Thanks...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.