468,463 Members | 2,041 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

Alias for a std::vector

I am trying to refer to the same std::vector in a class by two different names,
I tried a union, and I tried a reference, I can't seem to get the syntax right.
Can anyone please help? Thanks
Aug 16 '06
56 4930

Peter Olcott wrote:
If you don't already know how to do it, I would guess that I would likely be
wrong. I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple. I would expect that you would know all the
little nuances that I have never learned, so I estimate that I am likely
incorrect.
If you never write a class that has any of:

a const data member
a reference data member
a member of class type that provides no default constructor
a member of class type that provides no assignment operator
a base class that provides no default constructor or for which the
default constructor is not appropriate in your context

and you're not worried about:

possible efficiency problems in default initialising then assigning to
members vs directly initialising as required
possibly violating the principle of least surprise when other people
read your code

then you can avoid using initialiser lists if you want to. But remove
any one of those caveats and you need to use the initialiser list. Once
you are using it for some objects out of necessity, there is a strong
argument for clarity and consistency that you should use it all the
time.

Gavin Deane

Aug 18 '06 #51
In article <RJaFg.1210$Tl4.311@dukeread06>,
Peter Olcott <ol****@att.netwrote:
>"Greg Comeau" <co****@panix.comwrote in message
news:ec**********@panix2.panix.com...
>In article <_30Fg.1162$Tl4.145@dukeread06>,
Peter Olcott <ol****@att.netwrote:
>>>"Greg Comeau" <co****@panix.comwrote in message
news:ec**********@panix2.panix.com...
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.

Let's assume this is true. Show us how to do it with assignment only
while still retaining all the semantics necessary. In that
description please also remember than C++ derived from C.

If you don't already know how to do it, I would guess that I would likely be
wrong. I have never needed to use the initializer list syntax until recently,
I try to keep my code very simple. I would expect that you would know all the
little nuances that I have never learned, so I estimate that I am likely
incorrect.
It is important to keep things simple. But
I suspect you've only been using a subset of C++, hence limiting
your C++ programming universe. Nothing wrong with that per se.
But the breadth and width of programming is immense, and C++ captures
various aspects of that. This limiting often results in things being
"not as they should seem." A year later you'll wonder how you ever
thought such things. :)
>>>level. Also, on this note, if the body of the ctor is so far
too large that may also be problematic in its own right.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 18 '06 #52
In article <11**********************@m73g2000cwd.googlegroups .com>,
Gavin Deane <de*********@hotmail.comwrote:
>
Peter Olcott wrote:
>If you don't already know how to do it, I would guess that I would likely be
wrong. I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple. I would expect that you would know all the
little nuances that I have never learned, so I estimate that I am likely
incorrect.

If you never write a class that has any of:

a const data member
a reference data member
a member of class type that provides no default constructor
a member of class type that provides no assignment operator
a base class that provides no default constructor or for which the
default constructor is not appropriate in your context

and you're not worried about:

possible efficiency problems in default initialising then assigning to
members vs directly initialising as required
possibly violating the principle of least surprise when other people
read your code

then you can avoid using initialiser lists if you want to. But remove
any one of those caveats and you need to use the initialiser list. Once
you are using it for some objects out of necessity, there is a strong
argument for clarity and consistency that you should use it all the
time.
Yep. So long as you mention it, folks may also wan tot have a look at
http://www.comeaucomputing.com/techtalk/#meminit
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 18 '06 #53

"Peter Olcott" <ol****@att.netwrote in message
news:RJaFg.1210$Tl4.311@dukeread06...
I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple.
For me, the initialization list is the _simpler_ choice. In any new class
that I write, I put everything I can there. I only write code in the body
of the constructor if I _have_ to.

And it seems logical to me, as well as simple. It's stating in explicit
terms exactly what the initial state of the object will be.

Assignments are changes to state, and until an object is initialized, it
doesn't make semantic sense to "change" its state.

(Plus, how would you specify a specific constructor to use in order to
initialize the base class from a derived class constructor, if you didn't
have the initializer list?)

-Howard
Aug 18 '06 #54

"Greg Comeau" <co****@panix.comwrote in message
news:ec**********@panix2.panix.com...
In article <d24Fg.1182$Tl4.813@dukeread06>,
Peter Olcott <ol****@att.netwrote:
>>Instead of C++ overloading the meaning of the term [initialization]
to make it mean something slightly different than what it means
everywhere else, C++ should have adopted the universal convention
of the meaning of this term.

I believe this is an operative sentence in this discussion.
Therefore, it would be helpful for you to define what the
alledged and/or actual definition is in your opinion. That
might help to reveal why there is a difference of discussion here.
>>If they want to have something slightly different than what
[initialization] means everywhere else, they could come up
with a different term.

You may have a point, but I suspect there is subset relationship
that exists due to to limitations whereby it is oft considered the rule,
but in actuality is "merely" a subset.
>>In any case there is no absolute
requirement for initialization lists, the same semantics could be
derived using the assignment operator.

Let's assume this is true. Show us how. And also why it is superior.
>>In the case of things such as references, this
initialization form of assignment would only be valid in declarations.

Hmm, seems to me you're already making special rules while at
the same time arguing such specialiality is unncessary and bad.
I'm certain you said that and I did not misinterpret it.
What I am calling for is to keep the communication conventions as uniform as
possible. Its okay for a language to define specialized operations on the
specialized elements of this language. What is not okay it to add yet another
incompatible meaning to a pre-existing commonly understood term. In other words
don't make the details of explaining aspects of the language any more difficult
than necessary.

Minimizing the divergence of common terminology and programming conventions
minimizes the learning curve, and eliminates wasted time. There is already a
commonly understood meaning and syntax for the initialization of things, don't
make a whole different way of doing this if it is at all possible to avoid.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Aug 18 '06 #55
In article <1x*********************@bgtnsc05-news.ops.worldnet.att.net>,
Howard <al*****@hotmail.comwrote:
>"Peter Olcott" <ol****@att.netwrote in message
news:RJaFg.1210$Tl4.311@dukeread06...
>I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple.

For me, the initialization list is the _simpler_ choice. In any new class
that I write, I put everything I can there. I only write code in the body
of the constructor if I _have_ to.

And it seems logical to me, as well as simple. It's stating in explicit
terms exactly what the initial state of the object will be.

Assignments are changes to state, and until an object is initialized, it
doesn't make semantic sense to "change" its state.

(Plus, how would you specify a specific constructor to use in order to
initialize the base class from a derived class constructor, if you didn't
have the initializer list?)
Exactly.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 19 '06 #56
In article <YMpFg.1481$Tl4.967@dukeread06>,
Peter Olcott <ol****@att.netwrote:
>"Greg Comeau" <co****@panix.comwrote in message
news:ec**********@panix2.panix.com...
>In article <d24Fg.1182$Tl4.813@dukeread06>,
Peter Olcott <ol****@att.netwrote:
>>>Instead of C++ overloading the meaning of the term [initialization]
to make it mean something slightly different than what it means
everywhere else, C++ should have adopted the universal convention
of the meaning of this term.

I believe this is an operative sentence in this discussion.
Therefore, it would be helpful for you to define what the
alledged and/or actual definition is in your opinion. That
might help to reveal why there is a difference of discussion here.
>>>If they want to have something slightly different than what
[initialization] means everywhere else, they could come up
with a different term.

You may have a point, but I suspect there is subset relationship
that exists due to to limitations whereby it is oft considered the rule,
but in actuality is "merely" a subset.
>>>In any case there is no absolute
requirement for initialization lists, the same semantics could be
derived using the assignment operator.

Let's assume this is true. Show us how. And also why it is superior.
>>>In the case of things such as references, this
initialization form of assignment would only be valid in declarations.

Hmm, seems to me you're already making special rules while at
the same time arguing such specialiality is unncessary and bad.
I'm certain you said that and I did not misinterpret it.

What I am calling for is to keep the communication conventions as uniform as
possible. Its okay for a language to define specialized operations on the
specialized elements of this language. What is not okay it to add yet another
incompatible meaning to a pre-existing commonly understood term. In other words
don't make the details of explaining aspects of the language any more difficult
than necessary.

Minimizing the divergence of common terminology and programming conventions
minimizes the learning curve, and eliminates wasted time. There is already a
commonly understood meaning and syntax for the initialization of things, don't
make a whole different way of doing this if it is at all possible to avoid.
I think I agree completely with what you just wrote....
certainly as a goal, and hopefully in practice when possible.
I just don't think it is coming into play in this case.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 19 '06 #57

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.