Template specialization of pointers with function pointers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil

    Template specialization of pointers with function pointers

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

    template <typename T>
    void func(T* p)
    {
    DoSomethingGene ric(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)
    {
    DoSomethingSpec ialWithFuncPtr( 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.
  • llewelly

    #2
    Re: Template specialization of pointers with function pointers

    cognito79@hotma il.com (Phil) writes:
    [color=blue]
    > Ok, I have a template function for any pointer to type T:
    >
    > template <typename T>
    > void func(T* p)
    > {
    > DoSomethingGene ric(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)
    > {
    > DoSomethingSpec ialWithFuncPtr( p);
    > }[/color]

    Yes. This compiles as-is with most modern compilers,
    [color=blue]
    >
    > but my compiler (Visual C++ 6) won't let me.[/color]

    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.)
    [color=blue]
    > I know VC6 is lacking in
    > support for templates, but I'd like to know if this is even legal
    > anyway.[/color]

    It's well-formed.

    Comment

    Working...