施工初始化清单 [英] construction initialization list
问题描述
我有一个派生自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屋!