大佬教程收集整理的这篇文章主要介绍了C对重载函数的不明确调用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
inline void MySafeStrncpy(char *strDest,size_t maxsize,const char *strsourcE) { if(maxsizE) { maxsize--; strncpy(strDest,strsource,maxsizE); strDest[maxsize]=0; } } inline void MySafeStrncpy(char *strDest,size_t maxDestSize,const char *strsource,size_t maxsourceSizE) { size_t minSize=(maxDestSize<maxsourceSizE) ? maxDestSize:maxsourceSize; MySafeStrncpy(strDest,minSize,strsourcE); } template <size_t size> void MySafeStrncpy(char (&strDest)[size],const char *strsourcE) { MySafeStrncpy(strDest,size,strsourcE); } template <size_t sizeDest,size_t sizesource> void MySafeStrncpy(char (&strDest)[sizeDest],const char (&strsourcE)[sizesource]) { MySafeStrncpy(strDest,sizeDest,sizesourcE); } template <size_t sizesource> void MySafeStrncpy(char *strDest,maxDestSize,sizesourcE); }
char threadname[16]; MySafeStrncpy(threadname,"MainThread"); error C2668: 'MySafeStrncpy' : ambiguous call to overloaded function > Could be 'void MySafeStrncpy<16,11>(char (&)[16],const char (&)[11])' > or 'void MySafeStrncpy<16>(char (&)[16],const char *)' > while trying to match the argument list '(char [16],const char [11])'
我在这做错了什么?
在确定调用哪个模板函数时,似乎编译器无法确定字符串文字“MainThread”是否应被视为const char *或const char [11].
我希望它将字符串文字视为const char [11]并选择void MySafeStrncpy< 16,11>(char(&)[16],const char(&)[11])变体,因为那是最安全的”.
以上是大佬教程为你收集整理的C对重载函数的不明确调用全部内容,希望文章能够帮你解决C对重载函数的不明确调用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。