A function pointer that points to a function that takes an object of a template class with said function pointer as template argument. Possible?

StackOverflow https://stackoverflow.com/questions/1082552

Question

x__x

I want to do something like this:

typedef long (* fp)(BaseWindow< fp > & wnd, HWND hwnd, long wparam, long lparam);

But I get a compile error:

error C2065: 'fp' : undeclared identifier

Is it possible to implement this somehow?

Was it helpful?

Solution

No it isn't, because the type of the template parameter would include itself. This would yield to an endless recursion in the type.

If instead of the class template specialization, you accept a base-class of it, that's very possible

struct TemplateBase {

};

typedef long (*fpType)(TemplateBase&, HWND, long, long);

template<fpType FP>
struct BaseWindow : TemplateBase {

};


long sampleFunc(TemplateBase &b, HWND hwnd, long wparam, long lparam) {
  ...
}

int main() {
    BaseWindow<sampleFunc> bw;
    sampleFunc(bw, ...);
}

What do you want to do with this?

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top