TheVTM
TheVTM

Reputation: 1590

"C4430: missing type specifier - int assumed" in a template function

This code is so simple, shouldnt it compile? I am really lost with this one.

#include <iostream>

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

int main()
{
    foo(3);

    return 0;
}

Error:

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

Upvotes: 4

Views: 5205

Answers (1)

Qaz
Qaz

Reputation: 61920

You're missing a return type for foo. Presumably, you want:

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

Upvotes: 10

Related Questions