📄 assignop.htm
字号:
<html>
<head>
<link rel=stylesheet href="styles.css" type="text/css">
<title>Assignment and computed assignment operators</title>
</head>
<body>
<h6 align=right>
<a href="submat.htm">Prev</a> |
<a href="manual.htm">Up</a> |
<a href="unaryop.htm">Next</a>
</h6>
<h2>Assignment and computed assignment operators</h2>
<p>
The following assignment and computed assignment operators are available for the matrix class.
</p>
<pre><code><a href="#o1">1</a>. matrix<T>& operator= (const matrix<T>& <i>m</i>);
<a href="#o2">2</a>. matrix<T>& operator= (const T& <i>e</i>);
<a href="#o3">3</a>. template <class X> matrix<T>& operator= (const matrix<X>& <i>m</i>);
<a href="#o4">4</a>. matrix<T>& operator+= (const matrix<T>& <i>m</i>);
<a href="#o5">5</a>. matrix<T>& operator-= (const matrix<T>& <i>m</i>);
<a href="#o6">6</a>. matrix<T>& operator*= (const matrix<T>& <i>m</i>);
<a href="#o7">7</a>. matrix<T>& operator/= (const matrix<T>& <i>m</i>);
<a href="#o8">8</a>. matrix<T>& operator*= (const T& <i>e</i>);
<a href="#o9">9</a>. matrix<T>& operator/= (const T& <i>e</i>);
</code></pre>
<h4>Parameter</h4>
<p>
<dl>
<dt><i>m</i></dt>
<dd>A matrix object.</dd>
<dt><i>e</i></dt>
<dd>A number of type T.</dd>
</dl>
</p>
<p>
<ol>
<li><a name="o1">Assigns the matrix <i>m</i> to the left-hand side matrix. The size of the matrices need not be equal.</li><br><br>
<li><a name="o2">Assigns the value of <i>e</i> to all elements of the left-hand side matrix.</li><br><br>
<li><a name="o3">Assigns the matrix <i>m</i> of type X to the left hand-side matrix. The compiler must have member template support for this operator to work.</li><br><br>
<li><a name="o4">Adds the matrix <i>m</i> to the left-hand side matrix. The matrices must be equal in row and column size, otherwise this operator throws <i>invalid_argument</i> exception if range checking is enabled.
</li><br><br>
<li><a name="o5">Subtracts the matrix <i>m</i> from the left-hand side matrix. The matrices must be equal in row and column size, otherwise, this operator throws <i>invalid_argument</i> exception if range checking is enabled.</li><br><br>
<li><a name="o6">Multiply the matrix <i>m</i> to the left-hand side matrix. The column number of left-hand side matrix must be equal to row number of right-hand side matrix, otherwise, this operator throws <i>invalid_argument</i> exception if range checking is enabled.</li><br><br>
<li><a name="o7">Performs a simulated division by multiplying the inverse of the matrix <i>m</i> to the left-hand side matrix. The column number of left-hand side matrix must be equal to row number of right-hand side matrix, and the right-hand side matrix must be non-singular. This operator may throw <i>invalid_argument</i> or <i>runtime_error</i> exception.
</li><br><br>
<li><a name="o8">Multiplies all elements of the left-hand side matrix by <i>e</i>.</li><br><br>
<li><a name="o9">Divides all elements of the left-hand side matrix by <i>e</i>.</li><br><br>
</ol>
</p>
<h5>Examples</h5>
<pre><code>typedef matrix<double> Matrix;
typedef matrix<complex<double> > CMatrix;
Matrix A, B(3,3);
CMatrix CA(3,3);
B.rand();
A = B;
A = 0.0;
CA = A;
CA += CA;
A *= 3.0;
A /= 2;
A -= B;
A *= B;
A /= B;
</code></pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -