Why these C++ cases instantiate different templates -


i trying write functionality need save different functions , later extract arguments' types. i'm using function signature template parameter. unexpected results. here's code:

#include <functional> #include <iostream>  template <class t> struct foo {     foo()     {         std::cout << "class t" << std::endl;     } };  template <class ret, class arg> struct foo<ret(arg)> {     foo()     {         std::cout << "ret(arg)" << std::endl;     } };  template <class t> void save(std::function<t>) {     new foo<t>(); }  int main(int argc, char* argv[]) {     std::function<void(void)> somefoo;     save(somefoo);     return 0; } 

so if variable somefoo function type void(void), instantiates first template, foo<t>. if change void(int), desired specialized template instantiated. why that?

in c++, having void argument same having no argument @ (unlike in c, way). match specialization ret(), can't match specialization ret(arg).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -