I don't get why this is not working:
template <typename T>
struct TypeWrapper
{
typedef T type;
};
template <>
struct TypeWrapper<char*>
{
typedef std::string type;
};
template <>
struct TypeWrapper<const char*>
{
typedef std::string type;
};
template <int N>
struct TypeWrapper<char[N]>
{
typedef std::string type;
};
template <int N>
struct TypeWrapper<const char[N]>
{
typedef std::string type;
};
class A
{
public:
template< typename T >
A( const typename TypeWrapper<T>::type& t )
{
// do smthing
std::cout << t << std::endl;
}
};
int main( void )
{
A a( 42 );
return 0;
}
I compile with Visual Studio 2010 and I get the following error:
error C2664: 'A::A(const A &)' : cannot convert parameter 1 from 'int' to 'const A &'
If I change the constructor of A to this one it works:
A( const T& t )
But I'd like to handle char* types as std::strings and possibly other type adjustements, whithouth duplicating the constructor (defining a constructor specific to each type, this works)