c++ - 无法从 main 调用函数模板,因为没有匹配的函数调用
问题描述
由于某种原因,我的代码无法调用我的模板... XCODE 一直告诉我没有匹配的函数可以调用“extra”
template<class T>
T extra(T prompt, T low, T high) {.....}
int main()
{
string prompt = "hi"
int low = 5;
int high = 50;
int value = extra(prompt, low, high);
解决方案
template<class T>
T extra(T prompt, T low, T high) { ... }
定义了一个函数,它接受 3 个类型T
的参数,所以所有的参数必须是相同的类型。当你打电话时情况并非如此
// string int int
int value = extra(prompt, low, high);
可以这样想:您可以将所有T
替换为std::string
或将它们全部替换为int
。在这两种情况下,参数都不匹配。
但是我无法提出解决方案,因为我不确定您打算做什么。
推荐阅读
- c# - 使用 WPF MVVM 更新与 DataGrid 控件(MaterialDesign 主题)绑定的数据并附加行为?
- javascript - 如何使用 WebUSB 获取设备描述符?
- vue.js - 如何使用 Nuxt.js 在 Vuex 中设置和使用路由器
- tomcat - 每天,catalina.out 文件都是空的(0 字节)。我重新启动tomcat并重新填充。第二天又是空的
- r - `R`在`Mojave`的`anaconda 3`中不起作用
- dialogflow-es - 谷歌操作列表选择匹配错误的意图
- circuit-sdk - 有没有办法创建一个用户不必登录的聊天框?
- python - 正则表达式在某些字符之前查找文本
- sql-server - 自 2000 年起的 SQL Server 7.0,视图定义的 DTS 损坏
- mysql - MySQL选择最大日期和确切日期的订单