在模板函数中"C4430:缺少类型说明符 - 假定为int"

The*_*VTM 4 c++ templates visual-studio-2012

这段代码很简单,不应该编译吗?我真的迷失了这个.

#include <iostream>

template<typename T> foo(T f)
{
    std::cout << f << std::endl;
}

int main()
{
    foo(3);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

main.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Run Code Online (Sandbox Code Playgroud)

chr*_*ris 10

你错过了一个返回类型foo.据推测,你想要:

                     vvvv
template<typename T> void foo(T f)
{                    ^^^^
    std::cout << f << std::endl;
}
Run Code Online (Sandbox Code Playgroud)