Is there any way I can construct an new object from the given object if the template parameters of both objects are identical at run-time? For example:
I have a template class with the declaration:
template<typename _Type1, typename _Type2> class Object;
Next, I have two instantiations of the template:
template class Object<char, int>;
template class Object<wchar_t, wint_t>;
Now, I want to write a member function such as:
template<typename _Type1, typename _Type2>
Object<char, int> Object<_Type1, _Type2>::toCharObject() {
if(__gnu_cxx::__are_same<_Type1, char>::__value)
return *this;
else {
//Perform some kind of conversion and return an Object<char, int>
}
}
I have tried a couple of techniques, such as using __gnu_cxx::__enable_if<__gnu_cxx::__are_same<_Type1, char>::__value, _Type1>::__type
in a copy constructor for the Oject
class, but I keep running into the error:
error: conversion from ‘Object<wchar_t, wint_t>’ to non-scalar type ‘Object<char, int>’ requested
Is there no way I can do this? Any help will be greatly appreciated!