Initialization of non-POD aggregates

  • Thread starter =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
  • Start date
?

=?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=

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

Victor Bazarov

Ney said:
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
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top