The best way to initialise members is to use initialise list. But you still need to pay attention to the member declaration order and initialise orders.
class PoreNetwork
{
private:
int Size; // note, put Size in front of States/Radiuses members
public:
PoreNetwork(int esize);
int getSize();
StateNetworkType States;
RadiusNetworkType Radiuses;
};
PoreNetwork::PoreNetwork(int esize)
: Size(esize), // important to initialise Size first
States(boost::extents[Size][Size][Size]),
Radiuses(boost::extents[Size][Size][Size])
{
cout << "esize = " << esize << endl;
}
If your do not initialise Size first, it's undefined behavior to initialise States and Radiuses and Size has not initialised with yet.
PoreNetwork::PoreNetwork(int esize)
: States(boost::extents[Size][Size][Size]), // Undefined behavior as Size is not initialised yet
Radiuses(boost::extents[Size][Size][Size]),
Size(esize)
If yo don't put Size in in front of States/Radiuses in the member list, you get compiler warning.