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

Initialization of non-POD aggregates

P: n/a
Hello.

My understanding is that the struct /ItemExtrato/ in the following test
program is an aggregate type. As such, one should be able to use a
brace-enclosed initializer list. This is true, despite the fact that the
struct is not a POD type. Could anyone confirm that I am not mistaken?

#include <string>

struct ItemExtrato
{
std::string data;
std::string historico;
std::string documento;
double valor;
int pontos;
int saldo;
};

int main()
{
ItemExtrato item =
{
"17/12/2005",
"Um teste",
"DOC001",
150.0,
10,
32
};
}

The reason I ask is because the above program compiles successfully with
one compiler [1] and fails with another [2]. I tend to believe the older
compiler is at fault.

[1] MS 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
[2] Borland C++ 5.6 for Win32

Thank you for your input,

--
Ney André de Mello Zunino
Dec 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ney André de Mello Zunino wrote:
My understanding is that the struct /ItemExtrato/ in the following
test program is an aggregate type. As such, one should be able to use
a brace-enclosed initializer list. This is true, despite the fact
that the struct is not a POD type. Could anyone confirm that I am not
mistaken?
You're not mistaken.
#include <string>

struct ItemExtrato
{
std::string data;
std::string historico;
std::string documento;
double valor;
int pontos;
int saldo;
};

int main()
{
ItemExtrato item =
{
"17/12/2005",
"Um teste",
"DOC001",
150.0,
10,
32
};
}
[..]


The code is well-formed.

V
Dec 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.