question on instantiation of template argument with local scope

Discussion in 'C++' started by ag, Jan 3, 2009.

  1. ag

    ag Guest

    gcc and Sun Studio do not allow this, why does Visual Studio?


    template <class T> class foo { };

    void f()
    {
    class bar { };
    foo<bar> x;
    }

    C:\work>c:\mingw\bin\g++ -v
    gcc version 3.4.2 (mingw-special)

    c:\mingw\bin\g++ -c 12735.cpp
    12735.cpp: In function `void f()':
    12735.cpp:6: error: `f()::bar' uses local type `f()::bar'
    12735.cpp:6: error: trying to instantiate `template<class T> class
    foo'
    12735.cpp:6: error: invalid type in declaration before ';' token


    $ CC -V
    CC: Sun C++ 5.5 2003/03/12
    $ CC -c 12735.cpp
    "12735.cpp", line 6: Error: The local type "bar" cannot be used as a
    template argument.
    1 Error(s) detected.

    $ CC -V
    CC: Sun C++ 5.7 2005/01/07
    $ CC -c 12735.cpp
    "12735.cpp", line 6: Error: The local type "bar" cannot be used as a
    template argument.


    C:\work>cl /c 12735.cpp
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08
    for 80x86
    Copyright (C) Microsoft Corporation. All rights reserved.

    12735.cpp

    C:\work>
     
    ag, Jan 3, 2009
    #1
    1. Advertising

  2. ag

    Anuj Guest

    No. What is the switch?

    > Probably because it's a language extension offered by MS.  Have
    > you tried disabling the extensions (enabled by default)?
     
    Anuj, Feb 11, 2009
    #2
    1. Advertising

  3. ag

    red floyd Guest

    On Feb 11, 12:47 pm, Anuj <> wrote:
    > No. What is the switch?
    >
    > > Probably because it's a language extension offered by MS.  Have
    > > you tried disabling the extensions (enabled by default)?


    RTFM or TFMSDN.
     
    red floyd, Feb 12, 2009
    #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. Fernando Cuenca
    Replies:
    4
    Views:
    2,537
    Gianni Mariani
    Sep 6, 2004
  2. Neelesh Bodas

    template instantiation with local type

    Neelesh Bodas, Dec 9, 2005, in forum: C++
    Replies:
    4
    Views:
    315
  3. Replies:
    1
    Views:
    587
    Salt_Peter
    Dec 25, 2006
  4. nw
    Replies:
    0
    Views:
    332
  5. nguillot
    Replies:
    5
    Views:
    539
Loading...

Share This Page