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?
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?
从本页上的相关链接部分: 如何键入定义以其自身类型的函数作为参数的函数指针?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.