Initialization of non-POD aggregates

Discussion in 'C++' started by =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=, Dec 17, 2005.

  1. 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
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=, Dec 17, 2005
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Dec 17, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajax Chelsea

    Is array of POD still a POD type?

    Ajax Chelsea, Dec 1, 2003, in forum: C++
    Replies:
    1
    Views:
    340
    Ron Natalie
    Dec 1, 2003
  2. Replies:
    6
    Views:
    458
    Ron Natalie
    Dec 11, 2005
  3. Old Wolf
    Replies:
    1
    Views:
    313
  4. pallav

    POD initialization

    pallav, Jun 19, 2007, in forum: C++
    Replies:
    4
    Views:
    461
    pallav
    Jun 20, 2007
  5. Himanshu Garg
    Replies:
    1
    Views:
    159
    Himanshu Garg
    Sep 21, 2003
Loading...

Share This Page