国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

Another way to handle array initialization

2019-11-17 05:44:35
字體:
來源:轉載
供稿:網友

  PROBLEM: bwh@kato.prl.ufl.edu (Brian Hook)

[...]

I STILL haven't gotten a good technical reason why
parameters to constrUCtors for arrays haven't been at least talked out (I'm
not a committee member, so I don't know if this has been shot down
informally, so if it has, forgive my lack of knowledge on this).

I even asked The Man himself, and his response was basically that he didn't
see much need for it. I know I run into instances on occasion where I want
to specify something that is constant over an entire array of objects. For
example, something even as simple as "name".

Object array1[100]("Member of array1");
Object array2[100]("Member of array2");

I suppose templates serve much the same purpose, but it just seems so
damned inconsistent to not have parameters to constructors for arrays!

Sure, there's the old trick:

Object::name = "Member of array1";
Object array[100];
Object::name = "Member of array2";
etc. etc.

Now if THAT ain't ugly, I don't know what is!


RESPONSE: kanze@us-es.sel.de (James Kanze), 6 Jul 94

The trick I use is slightly different:

template< double r , double i >
class ComplexWithInit : public Complex
{
public :
ComplexWithInit()
: Complex( r , i ) {}
} ;

Complex* c1 = new ComplexWithInit< 1.0 , 2.0 >[ 10 ] ;
Complex* c2 = new ComplexWithInit< 3.0 , 4.0 >[ 20 ] ;

Formally speaking, this is *not* guaranteed to work. Practically, I
would be interested in hearing about a plausible implementation where
it will not actually work. (Finding the correct standardese which
would permit guaranteeing this to work without causing problems
elsewhere is a non-trivial problem, however.)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大港区| 望江县| 凤翔县| 溆浦县| 襄樊市| 外汇| 昌宁县| 静海县| 志丹县| 原平市| 桦川县| 武安市| 南投县| 叙永县| 青田县| 日喀则市| 赫章县| 兰西县| 石阡县| 瑞丽市| 饶河县| 黄山市| 丰县| 宣恩县| 江安县| 嵩明县| 东安县| 锡林郭勒盟| 榕江县| 信宜市| 东山县| 图们市| 时尚| 岳阳县| 拜泉县| 常熟市| 太保市| 仁布县| 五原县| 麻阳| 溆浦县|