Templated function pointer problem

I've been using VS for a while, but I just switched to GCC and am trying to sort of iron out a few wrinkles in it.

This one has me stumped:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class A
{
    public:
    int func(int v) { return v; }
};

template <typename T>
class Test
{
public:
    typedef T (A::*funcptr_t)(T);

    funcptr_t fnc;
};

template <typename T>
void gives_me_an_error()
{
    Test<T>::funcptr_t ptr;
}


line 19 gives me the error:

error: expected `;' before ‘ptr

This same code works fine in VS, and works fine if I remove the template parts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class A
{
    public:
    int func(int v) { return v; }
};

class Test
{
public:
    typedef int (A::*funcptr_t)(int);

    funcptr_t fnc;
};

void works_fine()
{
    Test::funcptr_t ptr;
}


Anyone have any idea what the problem is and/or if what I'm doing is legal? And/or how to solve (if possible)?

Thanks in advance.


EDIT --

nevermind. I worked around it by making gives_me_an_error a static member of Test, rather than a global function.. which is probably better design anyway.

Thanks anyway.
Last edited on
change line 19 to

typename Test<T>::funcptr_t ptr;

Topic archived. No new replies allowed.