Is there a way to pass template arguments to a function on an object when the object type is a template argument?
To illustrate:
struct MyFunc {
template <size_t N>
void doIt() {
cout << N << endl;
}
};
template <typename Func>
struct Pass123ToTemplateFunc {
static void pass(Func f) {
f.doIt<123>(); // <-- Error on compile; is there a way to express this?
}
};
int main() {
Pass123ToTemplateFunc<MyFunc>::pass(MyFunc());
return 0;
}
This is pretty much purely a syntax curiosity; is there a way in the language to express this without passing arguments to the doIt
function itself? If not, it's no big deal and I'm already well aware of ways I can gracefully 开发者_开发知识库work around it, so no need to provide alternative solutions. (I'll accept "no" as an answer, in other words, if that's the truth. :-P)
You have to tell the compiler that doIt
will be a template:
f.template doIt<123>();
精彩评论