Local structs as template parameters

Discussion in 'C++' started by Marcin Kalicinski, May 26, 2004.

  1. 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
     
    Marcin Kalicinski, May 26, 2004
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, May 26, 2004
    #2
    1. Advertising

  3. Marcin Kalicinski

    tom_usenet Guest

    tom_usenet, May 26, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patricia  Van Hise

    structs with fields that are structs

    Patricia Van Hise, Apr 5, 2004, in forum: C Programming
    Replies:
    5
    Views:
    642
    Al Bowers
    Apr 5, 2004
  2. Chris Hauxwell

    const structs in other structs

    Chris Hauxwell, Apr 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    561
    Chris Hauxwell
    Apr 27, 2004
  3. Paminu
    Replies:
    5
    Views:
    646
    Eric Sosman
    Oct 11, 2005
  4. Daniel Rudy
    Replies:
    15
    Views:
    1,408
    Keith Thompson
    Apr 10, 2006
  5. kito
    Replies:
    2
    Views:
    417
Loading...

Share This Page