Member Function Pointer with variable arguments as a template parameter?

I'm trying to store an arbitrary member function pointer.
Nothing about the function pointer is known beforehand.
I don't know what's the correct syntax for achieving this.

The following code will try to provide a better example of what I mean.
Please take into consideration this is not the actual code, but a short example of what it looks like.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

template <typename RetVal, typename Class, typename ... Args>
void FixThis( RetVal (Class::* fptr)(Args...) ) // (1)
{
    std::cout << static_cast<void*>(fptr) << std::endl;
    std::cout <<
        typeid(RetVal).name() << ' ' <<
        typeid(Class).name() << std::endl; // No args since they're packed.
}

int main()
{
    // Is FixThis<std::string::size_type, std::string, etc.> required?
    FixThis( &std::string::copy ); // (2)
}


What's the correct declaration for the FixThis parameter? (See pt. 1)
What's the correct way to call FixThis, and do I need to explicitly state the template parameters? (See pt. 2)

EDIT: Kinda resolved.
Apparently, std::string::copy is cv-incompatible.
This meant I had to change Point 1 to:
void FixThis( RetVal (Class::* fptr)(Args...) const).
Point 2 was good to go.
Last edited on
copy is a const qualified. Hence the signature of FixThis(....) needs to look like this:

void FixThis( RetVal (Class::* fptr)(Args...) const ) // (1)
Yeah, damnit.

I've received error messages for two days and changed parameter wording multiple times.
Today I gave up reading error messages for a second... just to find out I had it 98% right.
Topic archived. No new replies allowed.