Template specialization of pointers with function pointers

Discussion in 'C++' started by Phil, Sep 16, 2003.

  1. Phil

    Phil Guest

    Ok, I have a template function for any pointer to type T:

    template <typename T>
    void func(T* p)
    {
    DoSomethingGeneric(p);
    }

    Can I specialize this template for pointers to functions (or pointers
    to member functions, or pointers to anything)? I would like to do
    something like this:

    typedef void (*FUNCPTR)();

    template <>
    void func(FUNCPTR p)
    {
    DoSomethingSpecialWithFuncPtr(p);
    }

    but my compiler (Visual C++ 6) won't let me. I know VC6 is lacking in
    support for templates, but I'd like to know if this is even legal
    anyway. Thanks.
    Phil, Sep 16, 2003
    #1
    1. Advertising

  2. Phil

    llewelly Guest

    (Phil) writes:

    > Ok, I have a template function for any pointer to type T:
    >
    > template <typename T>
    > void func(T* p)
    > {
    > DoSomethingGeneric(p);
    > }
    >
    > Can I specialize this template for pointers to functions (or pointers
    > to member functions, or pointers to anything)? I would like to do
    > something like this:
    >
    > typedef void (*FUNCPTR)();
    >
    > template <>
    > void func(FUNCPTR p)
    > {
    > DoSomethingSpecialWithFuncPtr(p);
    > }


    Yes. This compiles as-is with most modern compilers,

    >
    > but my compiler (Visual C++ 6) won't let me.


    It's time you got out of the pleistocene and got into the
    holocene. You can get a better compiler from www.mingw.org,
    www.bloodshed.net, and many other places. (You can even get one
    from M$, provided you pay enough.)

    > I know VC6 is lacking in
    > support for templates, but I'd like to know if this is even legal
    > anyway.


    It's well-formed.
    llewelly, Sep 16, 2003
    #2
    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. Dave
    Replies:
    4
    Views:
    7,645
    pdixtl
    Jun 4, 2010
  2. Ruben Campos
    Replies:
    3
    Views:
    6,447
  3. Joseph Turian
    Replies:
    4
    Views:
    566
    John Carson
    Mar 20, 2006
  4. Joseph Turian
    Replies:
    2
    Views:
    454
  5. Replies:
    2
    Views:
    333
Loading...

Share This Page