施工初始化清单 [英] construction initialization list

查看:74
本文介绍了施工初始化清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个派生自Array类的Matrix类,如下所示:

Matrix(int nM,int nN)

:Array< T>(nM * nN) ,mnM(nM),mnN(nN)

{

}

但是,如果nM!= nN,我不想调用Array构造函数。在其他

字样中,我不想使用初始化列表。

问候

解决方案

bl**********@gmail.com 写道:

我有一个派生自Array类的Matrix类,如下所示:
Matrix(int nM,int nN)
:Array< T>(nM * nN),mnM( nM),mnN(nN)

然而,如果nM!= nN,我不想调用Array构造函数。换句话说,我不想使用初始化列表。




好​​的。现在我们知道你不想要什么。 *你想要什么*代替?


我的问题是有另一种方法使用描述的初始化列表调用没有

的Array构造函数?


bl ***** *****@gmail.com 写道:

我的问题是有另一种方法使用描述的初始化列表调用Array构造函数吗?




如果你没有把它放到初始化列表中,它将是

默认初始化。您可以随时尝试


:数组< T>(nM == nN?nM * nN:1),mnM(nM),mnN(nN)

{

//做一些关于nM不等的事情nN

}


V


I have a Matrix class derived from an Array class as followed:
Matrix(int nM, int nN)
:Array<T>(nM*nN),mnM(nM),mnN(nN)
{
}
However, I dont want to call Array constructor if nM!=nN. In other
words, I dont want to use the initialization list.
Regards

解决方案

bl**********@gmail.com wrote:

I have a Matrix class derived from an Array class as followed:
Matrix(int nM, int nN)
:Array<T>(nM*nN),mnM(nM),mnN(nN)
{
}
However, I dont want to call Array constructor if nM!=nN. In other
words, I dont want to use the initialization list.



OK. Now we know what you *don''t* want. What *do* you want [instead]?


My question is is there another way to call Array constructor without
using the described initialization list ?


bl**********@gmail.com wrote:

My question is is there another way to call Array constructor without
using the described initialization list ?



If you don''t put it into the initialiser list, it will be
default-initialised. You can always try doing

:Array<T>(nM == nN ? nM*nN : 1),mnM(nM),mnN(nN)
{
// do something about nM not being equal nN
}

V


这篇关于施工初始化清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆