草庐IT

PrintSmaller

全部标签

c++ - 带有 if 语句的 auto 函数不会返回值

我制作了一个模板和一个auto函数,用于比较2个值并返回最小值。这是我的代码:#includeusingnamespacestd;//Templatewithavaluereturningfunction:PrintSmallertemplateautoPrintSmaller(TNumOne,UNumTwo){if(NumOne>NumTwo){returnNumTwo;}else{returnNumOne;}}intmain(){intiA=345;floatfB=23.4243;cout但它无法编译,我在VS2015上遇到此错误:错误C3487“int”:所有返回表达式必须推导出