364,036 Members | 5027 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Alias for a std::vector

Peter Olcott
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


Aug 16 '06 #1
Share this Question
Share on Google+
56 Replies


Victor Bazarov
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


Aug 16 '06 #2

Peter Olcott
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
>
>

Aug 16 '06 #3

Jim Langston
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;


Aug 16 '06 #4

Peter Olcott
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.


Aug 16 '06 #5

Ian Collins
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.
Aug 16 '06 #6

Peter Olcott
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.

Aug 16 '06 #7

Peter Olcott
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.


Aug 16 '06 #8

Peter Olcott
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




Aug 16 '06 #9

Salt_Peter
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
*/

Aug 16 '06 #10

Peter Olcott
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.


Aug 16 '06 #11

Victor Bazarov
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


Aug 16 '06 #12

Victor Bazarov
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


Aug 16 '06 #13

Ian Collins
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.
Aug 16 '06 #14

Peter Olcott
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.


Aug 16 '06 #15

Peter Olcott
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
>
>

Aug 16 '06 #16

Jerry Coffin
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.
Aug 16 '06 #17

Peter Olcott
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
>
>

Aug 16 '06 #18

Jim Langston
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
>>
>>
>
>

Aug 16 '06 #19

Victor Bazarov
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


Aug 16 '06 #20

Peter Olcott
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
>

Aug 17 '06 #21

Greg Comeau
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?
Aug 17 '06 #22

Peter Olcott
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?

Aug 17 '06 #23

Thomas J. Gritzan
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
Aug 17 '06 #24

Victor Bazarov
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


Aug 17 '06 #25

56 Replies

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++