所以我试图在 Windows 中获取剪贴板的内容,因为它可以是任何类型,我使用模板来获取它,但是在尝试构建时,Visual Studio 2013 RC 发送此错误:
Error 1 error C2440: 'return' : cannot convert from 'char *' to 'double'
Error 2 error C2440: 'return' : cannot convert from 'double' to 'char *'
Error 3 error C2440: 'return' : cannot convert from 'int' to 'char *'
Warning 4 warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data
Error 5 error C2440: 'return' : cannot convert from 'char *' to 'int'
继承人的代码:
template<typename tn>
tn GetClipboardContents()
{
HANDLE h_clip;
double d_clip;
int i_clip;
char* str_clip;
if (OpenClipboard(NULL))
{
h_clip = GetClipboardData(CF_TEXT);
if (typeid(tn).name() == "double")
{
d_clip = atof((char*)h_clip);
}else if (typeid(tn).name() == "int"){
i_clip = atoi((char*)h_clip);
}else{
str_clip = (char*)h_clip;
}
CloseClipboard();
}
if (typeid(tn).name() == "double")
return d_clip;
else if (typeid(tn).name() == "int")
return i_clip;
else
return str_clip;
}
提前致谢。