c++ - 在模板类中使用友元运算符重载函数,错误未定义引用
问题描述
这是我的代码和声明,我不确定如何使用模板类正确设置友元函数。有人可以指导我做错了什么,为什么?
谢谢!
private:
int size;
T* buff;
friend Vector<T> operator * (const int n, const Vector<T> & v);
friend Vector<T> operator + (const int n, const Vector<T> & v);
template<typename T>
Vector<T> operator * (const int n, const Vector<T> & v){
Vector<T> vec(v.size);
vec.size = v.size;
for(int i = 0;i<vec.size;i++){
vec.buff[i] = v.buff[i]*n;
}
}
template<typename T>
Vector<T> operator+ (const int n, const Vector<T> & v){
Vector<T> vec(v.size);
vec.size = v.size;
for(int i = 0;i<vec.size;i++){
vec.buff[i] = v.buff[i]*n;
}
}
解决方案
推荐阅读
- mysql - 无法启动 mySQL “mysqld:参数太多(第一个额外是 'start')。”
- php - 使用 Symfony Finder 通过丢失文件排除目录
- python - Python - 语法无效
- c# - 从配置文件中获取设置
- nginx - 如何进行 nginx url 重写?
- swift - 有没有办法结合开关和包含?
- algorithm - 生成由c ++中整数的二进制表示给出的集合的所有子集
- ionic3 - ionic3 android构建错误:超时等待锁定
- ibm-watson - Watson Assistant - 提示所需的插槽不起作用
- django - 为什么 django inspectdb 不能在现有数据库上正确创建外键?