Unions : invalid types

This is a discussion on Unions : invalid types within the C Programming forums, part of the General Programming Boards category; Getting this error: error: field ‘circle’ has incomplete type I get this error for all the shapes in my union; ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    Unions : invalid types

    Getting this error:
    error: field ‘circle’ has incomplete type

    I get this error for all the shapes in my union; the code is as follows:
    Code:
    typedef struct circle {
            /* add the missing fields */
    	float x, y;
    	long radius;
    } CIRCLE;
    
    struct geomObj {
             union {
                     struct CIRCLE circle;
                     struct SQUARE square;
                     struct RECTANGLE rect;
                     struct TRIANGLE tri;
             };
    
             int id;
             short type;
    };
    All my other structures are defined similar to CIRCLE, just with different variables and names. Just wondering what I'm doing wrong

    Thanks in advance,

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    When you use typedef when defining a struct, as you did, it will suffice only to say:

    Code:
    CIRCLE aCircle;
    While it gives you an error if you do

    Code:
    struct CIRCLE aCircle;
    As it's already typedefined.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    Thanks very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid types 'int[int]' for array subscript
    By kolistivra in forum C++ Programming
    Replies: 6
    Last Post: 12-11-2010, 12:57 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 03:25 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21