473,471 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reference + initialiser oddity.

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
3 1266
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gavin Andrews | last post by:
I use log4j for logging and tend to include the following snipet in all my classes... public class MyClass { // Logging Declarations private static String _className; private static Category...
2
by: John Harrison | last post by:
What are the rule concerning calling member functions from an initialiser list? Suppose I have class C : public B { public: C() : x(), y(f()), z() {} private: Y f(); X x;
0
by: Tim Sharrock | last post by:
We have hit an internal compiler error when processing a very long array initialiser (for a lookup table). Most of the compiler versions we tried compiled the code successfully, but very slowly...
5
by: Andrew Poulos | last post by:
If I have some code in a function that looks something like this: if (x) { for (var i = 0; i < a; i++) { //blah } } else { for (var i = 0; i < b; i++) { //blah }
5
by: jmdocherty | last post by:
All, I've been trying to set up a CSS layout and all seems well in Firefox but in Safari it just seems to be plain weird! I hope someone can help tell me whether this is a problem with my code...
1
by: Alasdair | last post by:
Hi, I'm wondering if there is any way of getting around the "too many initialiser" error when giving initial values for an array. I'm trying to make a random word generator, so I need long lists of...
1
by: Frederick Gotham | last post by:
I have set up an online poll: http://snappoll.com/poll/130337.php to ask C++ programmers whether they want aggregate initialiser syntax to be added to the Standard. Here's is how it works: ...
22
by: Tomás Ó hÉilidhe | last post by:
I've been developing a C89 microcontroller application for a while now and I've been testing its compilation using gcc. I've gotten zero errors and zero warnings with gcc, but now that I've moved...
21
by: Ray Cassick | last post by:
I can't believe why I had not noticed this before and why I never asked it before... When defining a string why is it not required to use the new keyword? Like: Dim a As String = New String ...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.