valarray数组类型的构造方法

转自> http://www.classnotes.cn/2515.html
**

valarray数组类型的构造方法

使用 valarray 定义可变数组有以下几种方法:

double gpa[5] = { 3.1, 3.5, 3.8, 2.9, 3.3 };
valarray<double> v1; /* 浮点数组,大小为0 ——① /
valarray v2( 8 ); /
整型数组,大小为8 ——② /
valarray v3( 10, 8 ); /
整型数组,大小为8,每个值初始化为10 ——③ /
valarray v4( gpa, 4 ); /
浮点数组,大小为4,每个值初始化为数组 gpa 的前4个值 ——④ /
valarray v5( v3 ); /
整型数组,同v3 ——⑤ */

当作为类中的元素的时候,生成构造函数的方法:
class Student
{
private:
typedef std::valarray ArrayDb;
std::string name;
ArrayDb scores;

public:
Student() : name( “ Null Student ” ), scores()
{} /* ——① /
explicit Student( const std::string & s ) : name( s ), scores()
{} /
——① /
explicit Student( int n ) : name( “ Nully ” ), scores( n )
{} /
——② /
Student( const std::string & s, int n ) : name( s ), scores( n )
{} /
——② /
Student( const std::string & s, const ArrayDb & a ) : name( s ), scores( a )
{} /
——⑤ /
Student( const char * str, const double * pd, int n ) : name( str ), scores( pd, n )
{} /
——④ */

};

**
转自> http://www.classnotes.cn/2515.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值