c++ - Aliasing a function definition - possible VS2013 bug? -
i alias function definition, shown in code below. there compiler error when first function parameter not primitive type. assuming compiler bug. thoughts? there workaround using pre-processor, not ideal. compile error is: error c2061: syntax error : identifier 'string'
#include <iostream> #include <string> #include <functional> void print1(int i, std::string s) { std::cout << s << << std::endl; } void print2(std::string s, int i) { std::cout << s << << std::endl; } int main() { using fundefn1 = void(int, std::string); // ok //using fundefn2 = void(std::string, int); // error c2061: syntax error : identifier 'string' // workaround... #define fundefn2 void(std::string, int) std::function<fundefn1> p1 = print1; std::function<fundefn2> p2 = print2; p2("hello world!", 42); p1(42, "hello world!"); return 0; }
Comments
Post a Comment