Important: Please read the Qt Code of Conduct -

Error "aggregate 'myStruct name has incomplete type and cannot be defined"

  • Hi guys,
    Need help with this error. How to create a workable solution.

    My problem.
    I'm upgrading parts of an applications old C-code (Interactive Unix & LNF UI) with a lot of structs into C++. That is I'm creating a new GUI and try to keep a MVC approach on it, using the old code behind the scene.
    Some structs have arrays and unions in them and that causes my Qt C++ code to fail with heading error.

    I think that if a redefine the struct in an .h file in my project I get around it and the code passes compilation.
    But that is wrong in my codebook!! One should only define things once, or am I wrong here ?

    Some code:
    //defined in old defines.h
    struct samp {
    long datum;
    float halt[10];
    // union inside the struct
    union exval {
    float sum[15];
    float avg[10];
    } exval;
    } ; // end of struct

    // instantiate from c++ in .cpp file
    #include "../path/defines.h

    struct samp [10];

    // use the samp variable

  • Lifetime Qt Champion


    Indeed, you should only define things once. In C/C++ you generally do it in a header file and include that header when need. So if your old code defines things in implementation files and you want to re-use them, then I don't see anything wrong in moving these definitions in a header file. Or did I misunderstand your question ?

  • @SGaist
    Hi, yes I think you missed my question, or did I miss-write it.

    I can't Move the definitions. Still need them in the old code.
    The old definitions.h are cluttered with defines and redefines ifndef aso. Other old projects and code rely on their presence.
    My reason is that I have binary written data on files and to read/write I need to use the old struct definitions. When I'm including old .h files, the compiler complaints on tons of C style coding, even if I use extern "C" {} capsulation's .

    If I use extern struct name; as well as extern struct name varname;* same problem "aggregate error" or tons och complaints. Feels like the circulare referensing some how.

    My idea (against my will) is to make a special class of the struct, keep it clean from include and redefine the struct inside there, on the .cpp top side. and implement methods to use them.
    What I've found out (from internet search) is that the error occurs when a struct declares to complicated properties like arrays or unions in my case ( see ex. code). The only solution I found is redefining in my own class.

    I'm asking to find out if you wise men who knows Qt C++ coding have any other ideas to solve the problem?
    Would you redefine in a class or do it in another way?

  • Lifetime Qt Champion

    OK, it's clearer now. Can you share some of the errors you are getting when building ?

  • Banned

    This post is deleted!