C++ C++;运算符重载以执行double*对象
我现在正在编写一个类来进行一系列矩阵运算,其中之一就是将一个矩阵乘以一个数字。我成功制作了Matrix*2 p.e.,但我想制作2*Matrix。可能吗?怎么做 这是第一个运算符重载(矩阵*double)的签名:C++ C++;运算符重载以执行double*对象,c++,C++,我现在正在编写一个类来进行一系列矩阵运算,其中之一就是将一个矩阵乘以一个数字。我成功制作了Matrix*2 p.e.,但我想制作2*Matrix。可能吗?怎么做 这是第一个运算符重载(矩阵*double)的签名: Matrix Matrix::operator*(const double&b)因此,您可以像这样重载operator*: class t { private: int f; public: t(const int& i) : f(i) {} frien
Matrix Matrix::operator*(const double&b)
因此,您可以像这样重载operator*
:
class t
{
private:
int f;
public:
t(const int& i) : f(i) {}
friend t& operator*(const int& a, t&);
int get() const
{
return f;
}
};
t& operator*(const int& a, t& obj)
{
obj.f *= a;
return obj;
}
int main()
{
t obj(5);
obj = 2 * obj;
std::cout << obj.get();
}
t类
{
私人:
int f;
公众:
t(常数int&i):f(i){}
友元t&运算符*(常数int&a,t&);
int get()常量
{
返回f;
}
};
t&O操作员*(常量int&a、t&obj)
{
对象f*=a;
返回obj;
}
int main()
{
t-obj(5);
obj=2*obj;
我可以推荐你阅读吗?尤其是关于。