Function pointers & template functions

Discussion in 'C++' started by DaKoadMunky, Jul 23, 2004.

  1. DaKoadMunky

    DaKoadMunky Guest

    My question relates to storing the addresses of functions generated by
    templates in pointers to functions.

    <CODE>

    template<class T>
    void Global() {}

    namespace ANamespace
    {
    template<class T>
    void InANamespace() {}
    }

    int main()
    {
    void (*fncPtr)() = Global<int>; //Compiles on both Comeau & MSVC++.NET

    fncPtr = ANamespace::InANamespace<int>; //Compiles on Comeau but not
    MSVC++.NET

    return 0;
    }

    </CODE>

    Using MSVC++.NET line 1 compiles but line 2 does not.

    Using the Comeau Online compiler @ http://www.comeaucomputing.com/tryitout/
    both lines compile.

    I am assuming that Comeau is correct, but you know what they say about making
    assumptions.

    Can anyone comment on the correct syntax and which compiler is correct?

    Thanks.
     
    DaKoadMunky, Jul 23, 2004
    #1
    1. Advertising

  2. "DaKoadMunky" <> wrote in message
    news:...

    > <CODE>
    >
    > template<class T>
    > void Global() {}
    >
    > namespace ANamespace
    > {
    > template<class T>
    > void InANamespace() {}
    > }
    >
    > int main()
    > {
    > void (*fncPtr)() = Global<int>; //Compiles on both Comeau &

    MSVC++.NET
    >
    > fncPtr = ANamespace::InANamespace<int>; //Compiles on Comeau but

    not
    > MSVC++.NET
    >
    > return 0;
    > }
    >
    > </CODE>
    >
    > Using MSVC++.NET line 1 compiles but line 2 does not.


    Compiles fine for me. Perhaps you are using version 7.0?

    Jonathan
     
    Jonathan Turkanis, Jul 23, 2004
    #2
    1. Advertising

  3. DaKoadMunky

    DaKoadMunky Guest

    >Compiles fine for me. Perhaps you are using version 7.0?

    7.0.9466 dated 2002.
     
    DaKoadMunky, Jul 23, 2004
    #3
  4. "DaKoadMunky" <> wrote in message
    news:...
    > >Compiles fine for me. Perhaps you are using version 7.0?

    >
    > 7.0.9466 dated 2002.
    >


    7.1 is when it became a first-class compiler.

    Jonathan
     
    Jonathan Turkanis, Jul 23, 2004
    #4
  5. (DaKoadMunky) wrote in message news:<>...

    > Using MSVC++.NET line 1 compiles but line 2 does not.
    > ...
    > Can anyone comment on the correct syntax and which compiler is correct?


    I've just tried your code using MSVC 7.1 (compiler version 13.10.3077)
    and everything is working fine.

    harald
     
    Harald Deischinger, Jul 23, 2004
    #5
    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. Phil
    Replies:
    1
    Views:
    666
    llewelly
    Sep 16, 2003
  2. S?ren Gammelmark
    Replies:
    1
    Views:
    1,964
    Eric Sosman
    Jan 7, 2005
  3. Hicham Mouline
    Replies:
    0
    Views:
    450
    Hicham Mouline
    Apr 23, 2009
  4. Hicham Mouline
    Replies:
    1
    Views:
    435
    Michael DOUBEZ
    Apr 24, 2009
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    711
Loading...

Share This Page