Как вернуть неизвестный заранее тип переменной шаблона при помощи ключевого слова auto ?
error C2672: 'GetValue': no matching overloaded function found
error C2783: '_Out GetValue(_In &)': could not deduce template argument for '_Out'
note: see declaration of 'GetValue'
error C2672: 'GetValue': no matching overloaded function found
error C2783: '_Out GetValue(_In &)': could not deduce template argument for '_Out'
note: see declaration of 'GetValue'
Код:
const unsigned short V_INT = 0;
const unsigned short V_DOUBLE = 1;
typedef unsigned short TYPE;
struct ESAMPLE
{
union
{
TYPE type;
union
{
int _INT;
double _DOUBLE;
};
};
};
template<typename _Out, typename _In>
inline _Out GetValue(_In& v)
{
switch (v.type)
{
case V_INT:
return v._INT;
case V_DOUBLE:
return v._DOUBLE;
}
}
int main()
{
ESAMPLE e;
e.type = V_INT;
e._INT = -128;
auto x = GetValue(e); // must return 'int'
ESAMPLE e2;
e.type = V_DOUBLE;
e._DOUBLE = 128;
auto x2 = GetValue(e2); // must return 'double'
}
Продвижение своими сайтами как стратегия роста и независимости