如标题错误,在编译如下代码的时候遇到的,经google得知,我用C编译器去编译C++代码造成的。
gcc C编译器, g++ C++编译器。
#include <stdio.h> template <class T> T returnSelf(T &v){ return v; } int main(){ int i = 1; float j = 2.0f; double k = 3.0; printf("i is :%d\n",returnSelf(i)); printf("j is :%f\n",returnSelf(j)); printf("k is :%f\n",returnSelf(k)); }以上程序的注意点:float和double的说明符都是%f