|
-
Mar 15th, 2002, 11:51 PM
#1
Thread Starter
Addicted Member
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...
-
Mar 16th, 2002, 12:07 AM
#2
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
-
Mar 16th, 2002, 01:03 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|