“C4430:missing type specifier-int assume”在模板函数中 [英] "C4430: missing type specifier - int assumed" in a template function

查看:312
本文介绍了“C4430:missing type specifier-int assume”在模板函数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;
}

错误:

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


推荐答案

缺少 foo 的返回类型。假设您想要:

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

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

这篇关于“C4430:missing type specifier-int assume”在模板函数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆