Hello
I am trying to implement a class for which there is a templated constructor that behaves differently depending on the type of its argument. In particular, it should distinguish between regular function pointers and member function pointers. My idea was to use SFINAE and the fact that function pointers cannot be cast to member function pointers and vice versa. My test program looks like this:
#include <iostream> struct A { int f() { return 0; } }; struct sf { template<typename T> sf(T t, char (*dummy)[ sizeof(reinterpret_cast<void(*)()>(static_cast<T>(0))) ] = 0) { std::cout << "first\n"; } template<typename T> sf(T t, char (*dummy)[ sizeof(reinterpret_cast<void(sf::*)()>(static_cast<T>(0))) ] = 0) { std::cout << "second\n"; } }; double z(int, int) { return -1.0; } int main() { sf tmp1(&A::f); sf tmp2(z); }
This compiles and runs fine with GCC, printing:
second first
Unfortunately, the TI compiler complains that
"C:/test.cpp", line 18: error #311: more than one instance of constructor "sf::sf" matches the argument list: function template "sf::sf(T, char (*)[4U])" function template "sf::sf(T, char (*)[8U])" argument types are: (int (A::*)()) "C:/test.cpp", line 19: error #311: more than one instance of constructor "sf::sf" matches the argument list: function template "sf::sf(T, char (*)[4U])" function template "sf::sf(T, char (*)[8U])" argument types are: (double (int, int))
Is this a bug?
Thanks in advance
Markus