S
Salt_Peter
Peter said:Greg Comeau said:Peter Olcott <[email protected]> said:Peter Olcott wrote:
[..]
The basic idea works, yet I don't know the required syntax for all of
my other constructors.
What is the syntax for an initializer list when the constructor has
parameters?
What book are you reading that doesn't describe parameterized c-tors
and their initialiser lists????
I figured it out. It was not merely parameterized constructors with
initialization lists, I have done this before. It was the case where the
constructor has a body far too large to be contained in the declaration. I
intentionally avoided paying attention to initialization lists because IMO
they
represent bad (non orthogonal) language design.
I don't understand. What you did was to ignore a cornerstone
feature of initialization because it was deemed bad language
design (why do you think so??) only to introduce same on another
It is bad language design (non orthogonal) because there are two entirely
different syntax ways of doing this. Initialization lists and assignment, the
former being the oddball.
No Sir, the former is a brilliant, efficient syntax. Why construct an
unitialized object and afterwards provide it with attributes when you
can build it once as required? Or construct an object and have to limit
or fix its attributes? Or loose the ability to construct and object
that requires const attributes.
Constructors are a cornerstone of C++ and init lists simplify the
construction syntax greatly. Ignoring the immense power that an init
list provides is foolhardy. Take as an example a simple template, for a
moment.
template < class T >
class N
{
T m_t;
public:
N( T t ) : m_t( t ) { }
~N() { }
};
int main()
{
N< int > n( 10 );
N< double > d(11.1);
N< char > c( 'a' ); // etc...
}
Init lists are too powerful and yet so simple_to_use to be ignored.