我有以下模板类:
template <typename T> class ResourcePool {
inline void return_resource(T& instance) {
/* do something */
};
};
然后,在我的main 函数中,我会:
ResoucePool<int> pool;
pool.return_resource(5);
我收到以下错误:
error: no matching function for call to `ResourcePool<int>::return_resource(int)`
知道我做错了什么吗?
最佳答案
在这次通话中
pool.return_resource(5);
创建了一个值为 5 的 int
类型的临时对象作为函数的参数。
临时对象不能与非常量引用绑定(bind)。
像这样声明函数
template <typename T> class ResourcePool {
inline void return_resource( const T& instance) {
/* do something */
};
};
关于C++ 模板类 : error: no matching function for call to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44305592/