D
Don Kim
In Meyer's EC++, Item 13, he offers this code snippet:
template<class T>
class Array {
public:
Array(int lowBound, int highBound);
....
private:
vector<T> data;
unsigned int size;
int lBound, hBound;
};
template<class T>
Array<T>::Array(int lowBound, int highBound)
: size(highBound - lowBound + 1), lBound(lowBound), hBound(highBound),
data(size) {}
He states that "class members are initialized in the order of their
declaration in the class; the order in which they are listed in a member
initialization list makes not a whit of difference". So in the "Array
template, data will always be initialized first, followed by size, lBound,
and hBound. Always".
I pretty much get what he is saying, but not clear as to why. Could anyone
elaborate or clarify? Thanks.
I'm trying to get my level of C++ knowledge to the next level, so I'm
reading both Stroupstrup's TCL and Meyer's EC++, which makes it very hard,
but rewarding.
-Don
template<class T>
class Array {
public:
Array(int lowBound, int highBound);
....
private:
vector<T> data;
unsigned int size;
int lBound, hBound;
};
template<class T>
Array<T>::Array(int lowBound, int highBound)
: size(highBound - lowBound + 1), lBound(lowBound), hBound(highBound),
data(size) {}
He states that "class members are initialized in the order of their
declaration in the class; the order in which they are listed in a member
initialization list makes not a whit of difference". So in the "Array
template, data will always be initialized first, followed by size, lBound,
and hBound. Always".
I pretty much get what he is saying, but not clear as to why. Could anyone
elaborate or clarify? Thanks.
I'm trying to get my level of C++ knowledge to the next level, so I'm
reading both Stroupstrup's TCL and Meyer's EC++, which makes it very hard,
but rewarding.
-Don