通过运算符重载实现矩阵乘法
Matrix Multiplication through operator overloading
当我运行它而不是两个矩阵的乘积时,此代码显示地址。
matrix matrix:: operator *(matrix x)
{
matrix c(m1,n2);
c.m=c.n=m;
for(int i=0;i<m1;i++)
{
for(int j=0;j<n2;j++)
{
c.a[i][j]=0;
for(int k=0;k<n1;k++)
{
c.a[i][j]+=(a[i][k]*x.a[k][j]);
}
}
}
return c;
}
对于两个矩阵,可以使用成员一元运算符*=,即:
matrix & operator *= (matrix const & q)
{
// ... your code to multiply "this" by q...
return *this;
}
或非成员二进制运算符:
matrix operator * (matrix p, matrix const & q)
{
return p *= q;
}
相关文章:
- 使用'+='运算符统一实现 C++ '+'运算符
- 如何在层次结构中实现运算符使用?
- 使用初始值设定项列表作为函数参数的类对象实现运算符 [] 的示例
- 为什么我不能使用在 Visual C++ 32 位中实现运算符无符号 int() 作为数组索引的类?
- 我想知道我将如何实现 + 运算符重载.我已经从我上一个问题中计算出 += 运算符重载
- 如何在抽象基类中实现运算符+
- 如何拆分标头和重载实现运算符
- 如何在不修改C 中的LHS参数的情况下实现` `运算符
- 实现运算符<=> 表示可选<T>
- 如何实现运算符重载
- C++对象 [实现] 运算符 == 错误
- 在类标头之外实现运算符重载 C++
- 函子 - 它们相对于未实现运算符的其他类具有什么能力 ( )
- 实现运算符的正确方法!=用于类外的模板作为一个免费函数
- 在抽象基类上实现运算符<
- 不清楚如何在从抽象基类派生的类中实现运算符重载
- 我应该如何在派生类对象的基类部分的基类中实现运算符重载
- 尝试实现运算符时出错<<?
- 实现运算符<< 带有类::工厂();
- 派生 istringstream 和实现运算符>>(string&)