Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Initialisation of a Structure, Can anyone see the Obvious?

Initialisation of a Structure, Can anyone see the Obvious?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bram van Kampen
    wrote on last edited by
    #1

    Hi, I have the following Code:

    This refuses to compile with the following error message:
    "error C2552: 'TestFieldItem' : non-aggregates cannot be initialized with initializer list".

    I must be doing something stupid, that I cannot see. Initialising Static Structures is the Cut and Trust of CPP!
    Can anyone see the Obvious?

    :)

    Bram van Kampen

    L 2 Replies Last reply
    0
    • B Bram van Kampen

      Hi, I have the following Code:

      This refuses to compile with the following error message:
      "error C2552: 'TestFieldItem' : non-aggregates cannot be initialized with initializer list".

      I must be doing something stupid, that I cannot see. Initialising Static Structures is the Cut and Trust of CPP!
      Can anyone see the Obvious?

      :)

      Bram van Kampen

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I just tried that and it compiled fine. Maybe there is something more that you are not showing us.

      B 1 Reply Last reply
      0
      • B Bram van Kampen

        Hi, I have the following Code:

        This refuses to compile with the following error message:
        "error C2552: 'TestFieldItem' : non-aggregates cannot be initialized with initializer list".

        I must be doing something stupid, that I cannot see. Initialising Static Structures is the Cut and Trust of CPP!
        Can anyone see the Obvious?

        :)

        Bram van Kampen

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        As a side note, why declare each member as const? You could instead write ...

        const struct DB_FIELD TestFieldItem =
        {
        "Key", // FieldName
        NULL, // DesignerComment
        0X00000000, // Field Flags
        13, // Field Type
        8, // Field Elt Size
        1, //Field Elt Count
        0, // Field Offset
        0 //Padding Char
        };

        B 1 Reply Last reply
        0
        • L Lost User

          As a side note, why declare each member as const? You could instead write ...

          const struct DB_FIELD TestFieldItem =
          {
          "Key", // FieldName
          NULL, // DesignerComment
          0X00000000, // Field Flags
          13, // Field Type
          8, // Field Elt Size
          1, //Field Elt Count
          0, // Field Offset
          0 //Padding Char
          };

          B Offline
          B Offline
          Bram van Kampen
          wrote on last edited by
          #4

          Point taken, and since discovered. There seems to be a C(PP) language ambiguity here, relating to aggregates. There is never a problem with:

          const int Var=512;

          Thanks for your reply, :)

          Bram van Kampen

          1 Reply Last reply
          0
          • L Lost User

            I just tried that and it compiled fine. Maybe there is something more that you are not showing us.

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #5

            No, Not much more to show, just an Old Compiler! It Cannot handle these things, but I found a workaround. Was frightening at the time! Thanks, :)

            Bram van Kampen

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups