|
P: n/a
|
Peter Olcott
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 | |
Share this Question
|
P: n/a
|
Victor Bazarov
Peter Olcott wrote:
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
See FAQ 5.8.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | | |
P: n/a
|
Peter Olcott
struct Test {
union {
std::vector<intFred;
std::vector<intCharlie;
};
};
struct Test2 {
union {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
};
Neither of these two compile
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:tfKdnSiQCerpBH_ZnZ2dnUVZ_o-dnZ2d@comcast.com...
Peter Olcott wrote:
>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
>
See FAQ 5.8.
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>
>
| | |
P: n/a
|
Jim Langston
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:tfKdnSiQCerpBH_ZnZ2dnUVZ_o-dnZ2d@comcast.com...
>Peter Olcott wrote:
>>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
>>
>See FAQ 5.8.
>>
>V
>--
>Please remove capital 'A's when replying by e-mail
>I do not respond to top-posted replies, please don't ask
"Peter Olcott" <olcott@att.netwrote in message
news:XVwEg.772$Tl4.125@dukeread06...
struct Test {
union {
std::vector<intFred;
std::vector<intCharlie;
};
};
>
>
struct Test2 {
union {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
};
>
Neither of these two compile
Please don't top post. I fixed the order of your post.
std::vector is a container. You can only use POD (Plain Old Data) in
unions, not classes or (probably) templates.
If you want Charlie to be an alias to Fred, make it a reference.
std::vector<intFred;
std::vector<int>& Charlie = Fred; | | |
P: n/a
|
Peter Olcott
"Jim Langston" <tazmaster@rocketmail.comwrote in message
news:W0xEg.601$FE.521@newsfe02.lga...
>"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
>news:tfKdnSiQCerpBH_ZnZ2dnUVZ_o-dnZ2d@comcast.com...
>>Peter Olcott wrote:
>>>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
>>>
>>See FAQ 5.8.
>>>
>>V
>>--
>>Please remove capital 'A's when replying by e-mail
>>I do not respond to top-posted replies, please don't ask
>
>
"Peter Olcott" <olcott@att.netwrote in message
news:XVwEg.772$Tl4.125@dukeread06...
>struct Test {
> union {
> std::vector<intFred;
> std::vector<intCharlie;
> };
>};
>>
>>
>struct Test2 {
> union {
> std::vector<intFred;
> std::vector<int>& Charlie = Fred;
> };
>};
>>
>Neither of these two compile
>
Please don't top post. I fixed the order of your post.
>
std::vector is a container. You can only use POD (Plain Old Data) in unions,
not classes or (probably) templates.
>
If you want Charlie to be an alias to Fred, make it a reference.
>
std::vector<intFred;
std::vector<int>& Charlie = Fred;
>
>
My second example above tries this, and it does not compile. | | |
P: n/a
|
Ian Collins
Peter Olcott wrote:
"Jim Langston" <tazmaster@rocketmail.comwrote in message
news:W0xEg.601$FE.521@newsfe02.lga...
>
>>
>>std::vector is a container. You can only use POD (Plain Old Data) in unions,
>>not classes or (probably) templates.
>>
>>If you want Charlie to be an alias to Fred, make it a reference.
>>
>>std::vector<intFred;
>>std::vector<int>& Charlie = Fred;
>>
>
My second example above tries this, and it does not compile.
>
No it doesn't, you still have them in a union.
--
Ian Collins. | | |
P: n/a
|
Peter Olcott
"Ian Collins" <ian-news@hotmail.comwrote in message
news:4kflukFbl58vU1@individual.net...
Peter Olcott wrote:
>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>news:W0xEg.601$FE.521@newsfe02.lga...
>>
>>>
>>>std::vector is a container. You can only use POD (Plain Old Data) in unions,
>>>not classes or (probably) templates.
>>>
>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>
>>>std::vector<intFred;
>>>std::vector<int>& Charlie = Fred;
>>>
>>
>My second example above tries this, and it does not compile.
>>
No it doesn't, you still have them in a union.
>
--
Ian Collins.
| | |
P: n/a
|
Peter Olcott
"Ian Collins" <ian-news@hotmail.comwrote in message
news:4kflukFbl58vU1@individual.net...
Peter Olcott wrote:
>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>news:W0xEg.601$FE.521@newsfe02.lga...
>>
>>>
>>>std::vector is a container. You can only use POD (Plain Old Data) in unions,
>>>not classes or (probably) templates.
>>>
>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>
>>>std::vector<intFred;
>>>std::vector<int>& Charlie = Fred;
>>>
>>
>My second example above tries this, and it does not compile.
>>
No it doesn't, you still have them in a union.
>
--
Ian Collins.
struct Test2 {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
That was just a cut-and-paste error. The above code does not compile. | | |
P: n/a
|
Peter Olcott
"Ian Collins" <ian-news@hotmail.comwrote in message
news:4kflukFbl58vU1@individual.net...
Peter Olcott wrote:
>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>news:W0xEg.601$FE.521@newsfe02.lga...
>>
>>>
>>>std::vector is a container. You can only use POD (Plain Old Data) in unions,
>>>not classes or (probably) templates.
>>>
>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>
>>>std::vector<intFred;
>>>std::vector<int>& Charlie = Fred;
>>>
>>
>My second example above tries this, and it does not compile.
>>
No it doesn't, you still have them in a union.
>
--
Ian Collins.
Here is the whole program and the error messages:
#include <vector>
struct Test2 {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
int main() {
}
O:\cpp>set echo on
O:\cpp>cl -GX -O2 t.cpp 1>Error
O:\cpp>type Error
t.cpp
T.CPP(7) : error C2327: 'Test2::Fred' : member from enclosing class is not a
type name, static, or enumerator
T.CPP(7) : error C2065: 'Fred' : undeclared identifier
T.CPP(7) : error C2864: 'Charlie' : only const static integral data members can
be initialized inside a class or struct | | |
P: n/a
|
Salt_Peter
Peter Olcott wrote:
"Jim Langston" <tazmaster@rocketmail.comwrote in message
news:W0xEg.601$FE.521@newsfe02.lga...
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:tfKdnSiQCerpBH_ZnZ2dnUVZ_o-dnZ2d@comcast.com...
>Peter Olcott wrote:
>>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
>>
>See FAQ 5.8.
>>
>V
>--
>Please remove capital 'A's when replying by e-mail
>I do not respond to top-posted replies, please don't ask
"Peter Olcott" <olcott@att.netwrote in message
news:XVwEg.772$Tl4.125@dukeread06...
struct Test {
union {
std::vector<intFred;
std::vector<intCharlie;
};
};
>
>
struct Test2 {
union {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
};
>
Neither of these two compile
Please don't top post. I fixed the order of your post.
std::vector is a container. You can only use POD (Plain Old Data) in unions,
not classes or (probably) templates.
If you want Charlie to be an alias to Fred, make it a reference.
std::vector<intFred;
std::vector<int>& Charlie = Fred;
>
My second example above tries this, and it does not compile.
As was explained, the second example implements a union with the
afore-mentioned consequences.
#include <iostream>
#include <ostream>
#include <vector>
struct Test
{
std::vector<intFred;
std::vector<int>& Charlie;
public:
Test() : Fred(), Charlie(Fred) { }
~Test() { }
void getLocations() const
{
std::cout << "&Fred = " << &Fred;
std::cout << "\n&Charlie = " << &Charlie;
std::cout << std::endl;
}
};
int main()
{
Test test;
test.getLocations();
return 0;
}
/*
&Fred = 006BFDD8
&Charlie = 006BFDD8
*/ | | |
P: n/a
|
Peter Olcott
"Salt_Peter" <pj_hern@yahoo.comwrote in message
news:1155703839.687388.91830@m79g2000cwm.googlegro ups.com...
>
Peter Olcott wrote:
>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>news:W0xEg.601$FE.521@newsfe02.lga...
>"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
>news:tfKdnSiQCerpBH_ZnZ2dnUVZ_o-dnZ2d@comcast.com...
>>Peter Olcott wrote:
>>>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
>>>
>>See FAQ 5.8.
>>>
>>V
>>--
>>Please remove capital 'A's when replying by e-mail
>>I do not respond to top-posted replies, please don't ask
>
>
"Peter Olcott" <olcott@att.netwrote in message
news:XVwEg.772$Tl4.125@dukeread06...
>struct Test {
> union {
> std::vector<intFred;
> std::vector<intCharlie;
> };
>};
>>
>>
>struct Test2 {
> union {
> std::vector<intFred;
> std::vector<int>& Charlie = Fred;
> };
>};
>>
>Neither of these two compile
>
Please don't top post. I fixed the order of your post.
>
std::vector is a container. You can only use POD (Plain Old Data) in
unions,
not classes or (probably) templates.
>
If you want Charlie to be an alias to Fred, make it a reference.
>
std::vector<intFred;
std::vector<int>& Charlie = Fred;
>
>
>>
>My second example above tries this, and it does not compile.
>
As was explained, the second example implements a union with the
afore-mentioned consequences.
>
#include <iostream>
#include <ostream>
#include <vector>
>
struct Test
{
std::vector<intFred;
std::vector<int>& Charlie;
public:
Test() : Fred(), Charlie(Fred) { }
~Test() { }
void getLocations() const
{
std::cout << "&Fred = " << &Fred;
std::cout << "\n&Charlie = " << &Charlie;
std::cout << std::endl;
}
};
>
int main()
{
Test test;
test.getLocations();
return 0;
}
>
/*
&Fred = 006BFDD8
&Charlie = 006BFDD8
*/
>
That was simply a cut-and-paste error. I posted the whole program and the
compiler error messages on a previous post. | | |
P: n/a
|
Victor Bazarov
Peter Olcott wrote:
"Ian Collins" <ian-news@hotmail.comwrote in message
news:4kflukFbl58vU1@individual.net...
>Peter Olcott wrote:
>>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>>news:W0xEg.601$FE.521@newsfe02.lga...
>>>
>>>>
>>>std::vector is a container. You can only use POD (Plain Old Data)
>>>in unions, not classes or (probably) templates.
>>>>
>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>>
>>>std::vector<intFred;
>>>std::vector<int>& Charlie = Fred;
>>>>
>>>
>>My second example above tries this, and it does not compile.
>>>
>No it doesn't, you still have them in a union.
>>
>--
>Ian Collins.
>
>
struct Test2 {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
>
That was just a cut-and-paste error. The above code does not compile.
Correct. Declarations of members shall not have any initialisation
unless they are of static integral constants. All initialisation has
to go to the constructor initialiser list.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | | |
P: n/a
|
Victor Bazarov
Peter Olcott wrote:
"Ian Collins" <ian-news@hotmail.comwrote in message
news:4kflukFbl58vU1@individual.net...
>Peter Olcott wrote:
>>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>>news:W0xEg.601$FE.521@newsfe02.lga...
>>>
>>>>
>>>std::vector is a container. You can only use POD (Plain Old Data)
>>>in unions, not classes or (probably) templates.
>>>>
>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>>
>>>std::vector<intFred;
>>>std::vector<int>& Charlie = Fred;
>>>>
>>>
>>My second example above tries this, and it does not compile.
>>>
>No it doesn't, you still have them in a union.
>>
>--
>Ian Collins.
>
Here is the whole program and the error messages:
>
#include <vector>
>
struct Test2 {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
Drop the "= Fred" portion, and add here:
Test2() : Charlie(Fred) {}
};
>
int main() {
}
>
>
O:\cpp>set echo on
>
O:\cpp>cl -GX -O2 t.cpp 1>Error
>
O:\cpp>type Error
t.cpp
T.CPP(7) : error C2327: 'Test2::Fred' : member from enclosing class
is not a type name, static, or enumerator
T.CPP(7) : error C2065: 'Fred' : undeclared identifier
T.CPP(7) : error C2864: 'Charlie' : only const static integral data
members can be initialized inside a class or struct
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | | |
P: n/a
|
Ian Collins
Peter Olcott wrote:
"Ian Collins" <ian-news@hotmail.comwrote in message
news:4kflukFbl58vU1@individual.net...
>
>>Peter Olcott wrote:
>>>
>>>My second example above tries this, and it does not compile.
>>>
>>
>>No it doesn't, you still have them in a union.
>>
>>--
>>Ian Collins.
>
>
Here is the whole program and the error messages:
>
#include <vector>
>
struct Test2 {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
>
int main() {
}
As shown else thread, you can't do this, a minimum solution is
struct Test2 {
std::vector<intFred;
std::vector<int>& Charlie;
Test2() : Charlie(Fred) {}
};
--
Ian Collins. | | |
P: n/a
|
Peter Olcott
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:cq6dnaMnIopkO3_ZnZ2dnUVZ_qSdnZ2d@comcast.com. ..
Peter Olcott wrote:
>"Ian Collins" <ian-news@hotmail.comwrote in message
>news:4kflukFbl58vU1@individual.net...
>>Peter Olcott wrote:
>>>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>>>news:W0xEg.601$FE.521@newsfe02.lga...
>>>>
>>>>>
>>>>std::vector is a container. You can only use POD (Plain Old Data)
>>>>in unions, not classes or (probably) templates.
>>>>>
>>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>>>
>>>>std::vector<intFred;
>>>>std::vector<int>& Charlie = Fred;
>>>>>
>>>>
>>>My second example above tries this, and it does not compile.
>>>>
>>No it doesn't, you still have them in a union.
>>>
>>--
>>Ian Collins.
>>
>>
>struct Test2 {
> std::vector<intFred;
> std::vector<int>& Charlie = Fred;
>};
>>
>That was just a cut-and-paste error. The above code does not compile.
>
Correct. Declarations of members shall not have any initialisation
unless they are of static integral constants. All initialisation has
to go to the constructor initialiser list.
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>
>
Ah that seems to be right, I will try it. | | |
P: n/a
|
Peter Olcott
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:u_qdnaalP_C4On_ZnZ2dnUVZ_qKdnZ2d@comcast.com. ..
Peter Olcott wrote:
>"Ian Collins" <ian-news@hotmail.comwrote in message
>news:4kflukFbl58vU1@individual.net...
>>Peter Olcott wrote:
>>>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>>>news:W0xEg.601$FE.521@newsfe02.lga...
>>>>
>>>>>
>>>>std::vector is a container. You can only use POD (Plain Old Data)
>>>>in unions, not classes or (probably) templates.
>>>>>
>>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>>>
>>>>std::vector<intFred;
>>>>std::vector<int>& Charlie = Fred;
>>>>>
>>>>
>>>My second example above tries this, and it does not compile.
>>>>
>>No it doesn't, you still have them in a union.
>>>
>>--
>>Ian Collins.
>>
>Here is the whole program and the error messages:
>>
>#include <vector>
>>
>struct Test2 {
>std::vector<intFred;
>std::vector<int>& Charlie = Fred;
>
Drop the "= Fred" portion, and add here:
>
Test2() : Charlie(Fred) {}
Yes that did it, thanks.
>
>};
>>
>int main() {
>}
>>
>>
>O:\cpp>set echo on
>>
>O:\cpp>cl -GX -O2 t.cpp 1>Error
>>
>O:\cpp>type Error
>t.cpp
>T.CPP(7) : error C2327: 'Test2::Fred' : member from enclosing class
>is not a type name, static, or enumerator
>T.CPP(7) : error C2065: 'Fred' : undeclared identifier
>T.CPP(7) : error C2864: 'Charlie' : only const static integral data
>members can be initialized inside a class or struct
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>
>
| | |
P: n/a
|
Jerry Coffin
In article <d5xEg.773$Tl4.593@dukeread06>, olcott@att.net says...
[ ... ]
struct Test2 {
union {
std::vector<intFred;
std::vector<int>& Charlie = Fred;
};
};
[ ... ]
My second example above tries this, and it does not compile.
This is still trying to put a vector<intinside of a union, and (as
already mentioned) you can only put PODs into unions. There's also the
minor detail that in-place initialization like you've tried to use above
can be used with things like static const variables, or with
enumerators, but not with normal data members. Try something like this:
struct Test3 {
std::vector<intFred;
std::vector<int&Charlie;
Test3() : Charlie(Fred) {}
};
....and there's a good chance your compiler will be happier.
--
Later,
Jerry.
The universe is a figment of its own imagination. | | |
P: n/a
|
Peter Olcott
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:u_qdnaalP_C4On_ZnZ2dnUVZ_qKdnZ2d@comcast.com. ..
Peter Olcott wrote:
>"Ian Collins" <ian-news@hotmail.comwrote in message
>news:4kflukFbl58vU1@individual.net...
>>Peter Olcott wrote:
>>>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>>>news:W0xEg.601$FE.521@newsfe02.lga...
>>>>
>>>>>
>>>>std::vector is a container. You can only use POD (Plain Old Data)
>>>>in unions, not classes or (probably) templates.
>>>>>
>>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>>>
>>>>std::vector<intFred;
>>>>std::vector<int>& Charlie = Fred;
>>>>>
>>>>
>>>My second example above tries this, and it does not compile.
>>>>
>>No it doesn't, you still have them in a union.
>>>
>>--
>>Ian Collins.
>>
>Here is the whole program and the error messages:
>>
>#include <vector>
>>
>struct Test2 {
>std::vector<intFred;
>std::vector<int>& Charlie = Fred;
>
Drop the "= Fred" portion, and add here:
>
Test2() : Charlie(Fred) {}
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?
>
>};
>>
>int main() {
>}
>>
>>
>O:\cpp>set echo on
>>
>O:\cpp>cl -GX -O2 t.cpp 1>Error
>>
>O:\cpp>type Error
>t.cpp
>T.CPP(7) : error C2327: 'Test2::Fred' : member from enclosing class
>is not a type name, static, or enumerator
>T.CPP(7) : error C2065: 'Fred' : undeclared identifier
>T.CPP(7) : error C2864: 'Charlie' : only const static integral data
>members can be initialized inside a class or struct
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>
>
| | |
P: n/a
|
Jim Langston
"Peter Olcott" <olcott@att.netwrote in message
news:1ZxEg.782$Tl4.716@dukeread06...
>
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:u_qdnaalP_C4On_ZnZ2dnUVZ_qKdnZ2d@comcast.com. ..
>Peter Olcott wrote:
>>"Ian Collins" <ian-news@hotmail.comwrote in message
>>news:4kflukFbl58vU1@individual.net...
>>>Peter Olcott wrote:
>>>>"Jim Langston" <tazmaster@rocketmail.comwrote in message
>>>>news:W0xEg.601$FE.521@newsfe02.lga...
>>>>>
>>>>>>
>>>>>std::vector is a container. You can only use POD (Plain Old Data)
>>>>>in unions, not classes or (probably) templates.
>>>>>>
>>>>>If you want Charlie to be an alias to Fred, make it a reference.
>>>>>>
>>>>>std::vector<intFred;
>>>>>std::vector<int>& Charlie = Fred;
>>>>>>
>>>>>
>>>>My second example above tries this, and it does not compile.
>>>>>
>>>No it doesn't, you still have them in a union.
>>>>
>>>--
>>>Ian Collins.
>>>
>>Here is the whole program and the error messages:
>>>
>>#include <vector>
>>>
>>struct Test2 {
>>std::vector<intFred;
>>std::vector<int>& Charlie = Fred;
>>
>Drop the "= Fred" portion, and add here:
>>
> Test2() : Charlie(Fred) {}
>
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?
Test2( int SomeInt, std::string SomeString ): Charlie( Fred ), OtherVar(
SomeInt ) { /*...*/ };
>
>>
>>};
>>>
>>int main() {
>>}
>>>
>>>
>>O:\cpp>set echo on
>>>
>>O:\cpp>cl -GX -O2 t.cpp 1>Error
>>>
>>O:\cpp>type Error
>>t.cpp
>>T.CPP(7) : error C2327: 'Test2::Fred' : member from enclosing class
>>is not a type name, static, or enumerator
>>T.CPP(7) : error C2065: 'Fred' : undeclared identifier
>>T.CPP(7) : error C2864: 'Charlie' : only const static integral data
>>members can be initialized inside a class or struct
>>
>V
>--
>Please remove capital 'A's when replying by e-mail
>I do not respond to top-posted replies, please don't ask
>>
>>
>
>
| | |
P: n/a
|
Victor Bazarov
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????
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | | |
P: n/a
|
Peter Olcott
"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
news:ebv2ej$mcv$1@news.datemas.de...
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.
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>
| | |
P: n/a
|
Greg Comeau
In article <zIQEg.929$Tl4.354@dukeread06>, Peter Olcott <olcott@att.netwrote:
>"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
>news:ebv2ej$mcv$1@news.datemas.de...
>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
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? | | |
P: n/a
|
Peter Olcott
"Greg Comeau" <comeau@panix.comwrote in message
news:ec1ohb$kod$1@panix2.panix.com...
In article <zIQEg.929$Tl4.354@dukeread06>, Peter Olcott <olcott@att.net>
wrote:
>>"Victor Bazarov" <v.Abazarov@comAcast.netwrote in message
>>news:ebv2ej$mcv$1@news.datemas.de...
>>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.
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?
| | |
P: n/a
|
Thomas J. Gritzan
Peter Olcott schrieb:
"Greg Comeau" <comeau@panix.comwrote in message
>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.
There are "two different syntax ways" for normal types:
int *pi = new int(5);
int i(5); // both: initialize i to 5
i = 5; // assign/reset i to 5
So there are two different ways for class members, too. It is not bad
language design, it is quite necessary.
By the way:
int& refi(i); // initialize int&
const int ci(7); // initialize const int
refi = &i; // can't bind to another object
ci = 11; // not possible, it's const
So references and const member variables have to use initialization list,
since assignment is not possible.
--
Thomas | | |
P: n/a
|
Victor Bazarov
Peter Olcott wrote:
[..]
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.
Very sorry to hear (read) that. You apparently do not understand
the difference. Read the FAQ, read more good books.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | | Post your reply Help answer this question
Didn't find the answer to your C / C++ question?
You can also browse similar questions: C / C++ | | Question stats - viewed: 1106
- replies: 56
- date asked: Aug 16 '06
|