Results 1 to 3 of 3

Thread: Structs, and Arrays...

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Question Structs, and Arrays...

    I want to make a struct that can hold an undifined array of other user defined structs.......

    Ex:
    Code:
    typedef struct Info_Holder
    {
        string         Name[];
        XHOLDER   xHolder[];   // another user defined struct
    
        Info_Holder()
        {
            xHolder[] = new xHolder();
        }
        ~Info_Holder()
        {
            delete[] xHolder;
        }
    }
    is that the right way to do it??? Can someone explain to me a better way cause this gives me errors...
    To protect time is to protect everything...

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    You appear to be using class syntax. A struct is just a user defined type. All data, no functions...
    Code:
    typedef struct Info_Holder
    {
        string         Name[];
        XHOLDER   xHolder[];   // another user defined struct
    }
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Zaei
    Guest
    In C++, the difference between a class and a struct is the default visibility of members. You must specifically define a group of functions or data to be public in a class, while in a struct that is the default. Otherwise, it is only convention that says classes have member functions and structs contain data.

    As for the original question:
    Code:
    ...
    XHOLDER* m_xData;
    ...
    Info_Holder() {
      m_xData = new XHOLDER[NUM_XHOLDERS];
    }
    ...
    ~Info_Holder() {
      delete [] m_xData;
    }
    You also dont have to typedef your structs in C++. In C it is a customary practice to typedef structs, because declaring a variable of a struct type directly looked like this:
    Code:
    struct myDataType myVarName;
    When you typedef:
    Code:
    typedef struct tagMyDataType{...} myDataType;
    you can then declare using this format:
    Code:
    mDataType myVarName;
    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width