operator* (<valarray>)
取得兩同樣大小的valarrays的對應項目的產品或之間valarray之間的值。
template<class Type>
valarray<Type> operator*(
const valarray<Type>& _Left,
const valarray<Type>& _Right
);
template<class Type>
valarray<Type> operator*(
const valarray<Type>& _Left,
const Type& _Right
);
template<class Type>
valarray<Type> operator*(
const Type& _Left,
const valarray<Type>& _Right
);
參數
_Left
項目要乘以的或要乘以的某個值與每個項目valarray的第一個valarrays。_Right
項目要乘以的或要乘以的某個值與每個項目valarray的第二個兩valarrays。
傳回值
項目是項目 _Left 產品和 _Right.的valarray
範例
// valarray_op_eprod.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 8 ), vaR ( 8 );
valarray<int> vaNE ( 8 );
for ( i = 0 ; i < 8 ; i += 2 )
vaL [ i ] = 2;
for ( i = 1 ; i < 8 ; i += 2 )
vaL [ i ] = -1;
for ( i = 0 ; i < 8 ; i++ )
vaR [ i ] = i;
cout << "The initial Left valarray is: ( ";
for (i = 0 ; i < 8 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
cout << "The initial Right valarray is: ( ";
for (i = 0 ; i < 8 ; i++ )
cout << vaR [ i ] << " ";
cout << ")." << endl;
vaNE = ( vaL * vaR );
cout << "The element-by-element result of "
<< "the multiplication is the\n valarray: ( ";
for (i = 0 ; i < 8 ; i++ )
cout << vaNE [ i ] << " ";
cout << ")." << endl;
}
需求
標題: <valarray>
命名空間: std