By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

Reference + initialiser oddity.

P: n/a
Kindly consider:

struct MyStruct
{
Foo* foo;
Bar& bar;
};

void Blah(Foo* foo, Bar& bar)
{
// create+initialise struct
MyStruct m = {foo, bar};
}
This works fine on a gcc port. However vc6/.net give this cryptic error:
'm' : non-aggregates cannot be initialized with initializer list.

It appears that it's the Bar& that's the problem, not the Foo*. Anyone able
to shed light on this for me?

thanks,
G.A.
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Glen Able wrote:
Kindly consider:

struct MyStruct
{
Foo* foo;
Bar& bar;
};

void Blah(Foo* foo, Bar& bar)
{
// create+initialise struct
MyStruct m = {foo, bar};
}
This works fine on a gcc port. However vc6/.net give this cryptic error:
'm' : non-aggregates cannot be initialized with initializer list.

It appears that it's the Bar& that's the problem, not the Foo*. Anyone able
to shed light on this for me?


VC++ has problems with brace-enclosed initialisers for aggregates.
The behaviour is somewhat fixed in the version 7.1 (I checked).

V
Jul 23 '05 #2

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:te*******************@newsread1.mlpsca01.us.t o.verio.net...
Glen Able wrote:
Kindly consider:

struct MyStruct
{
Foo* foo;
Bar& bar;
};

void Blah(Foo* foo, Bar& bar)
{
// create+initialise struct
MyStruct m = {foo, bar};
}
This works fine on a gcc port. However vc6/.net give this cryptic error: 'm' : non-aggregates cannot be initialized with initializer list.

It appears that it's the Bar& that's the problem, not the Foo*. Anyone able to shed light on this for me?


VC++ has problems with brace-enclosed initialisers for aggregates.
The behaviour is somewhat fixed in the version 7.1 (I checked).


Right, so my code's all good and legal - hurrah!

thanks,
G.A.
Jul 23 '05 #3

P: n/a
Glen Able wrote:
struct MyStruct
{
Foo* foo;
Bar& bar;
};

void Blah(Foo* foo, Bar& bar)
{
// create+initialise struct
MyStruct m = {foo, bar};
}
This works fine on a gcc port. However vc6/.net give this cryptic error:
'm' : non-aggregates cannot be initialized with initializer list.

It appears that it's the Bar& that's the problem, not the Foo*. Anyone able
to shed light on this for me?

Your code compiles with VC++ 7.1. Provided that I provide a definition
for both Foo and Bar.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.