I have a function set_datathat I have to implement differently for the different types in which it accepts. For example, this is an attempt to implement two overloads based on the input type. If this is fundamental, neither voidand not nullptr_t, then process it in the first implementation. If it is a buffer std::stringor char, process it in the second way.
struct field
{
template<typename TDataType, typename=void>
void set_data(TDataType data, size_t index = 0);
};
template<typename TDataType, typename = typename
std::enable_if< std::is_fundamental<TDataType>::value &&
std::is_same<TDataType, nullptr_t>::value == false &&
std::is_same<TDataType, void>::value == false>::type>
void field::set_data(TDataType data, size_t index )
{
}
template<typename TDataType, typename = typename
std::enable_if< std::is_same<std::string const &, TDataType> ||
std::is_same<char const *, TDataType>>::type>
void field::set_data(TDataType data, size_t index )
{
}
Then I call:
field f;
int x = 10;
f.set_data(x);
And the compiler gives me an error.
defs.h(111): error C2995: 'void messaging::field::set_data(TDataType,size_t)' : function template has already been defined
How to resolve this?
At visual studio 2013
source
share