Reference + initialiser oddity.

G

Glen Able

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.
 
V

Victor Bazarov

Glen said:
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
 
G

Glen Able

Victor Bazarov said:
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.
 
I

Ioannis Vranos

Glen said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top