-
In need of some help
Hi all, I'm relatively new to C++ programming.....
Can some please explain to me what the following lines of code exactly do?
//I know this is a constructor but the syntax is confusing...
THMT::THMT(int ns, int nc, int nl, bool zm)
:M(ns), nCh(nc), nLev(n1), zeromean(zm),
model_trans(nLev, matrix<double>(M,M),
model_mean(nLev, vector<double>(M)),
model_stdv(nLev, vector<double>(M))
{
rnd_init_model();
}
-
That's an initializer list
Code:
MyClass :: MyClass ( int var1, int var2, int var3 ) :
member1 ( var1 ), member2 ( var2 ), member3 ( var3 )
{
// Initialize class members
}
is equivalent to
Code:
MyClass :: MyClass ( int var1, int var2, int var3 )
{
// Initialize class members
member1 = var1;
member2 = var2;
member3 = var3;
}
Initializer lists tend to be more efficient and compact, but the syntax is confusing to some.
-Prelude
-
Thanks for the reply!
Appreciate it!