Default constructor for nested struct in a class?
In striving to organize the members of my class to make them more intuitive when accessed later on, I seem to have encountered a small problem. Maybe I''m way off the mark and it simply can''t/shouldn''t be done, in which case I''d appreciate any suggestions for a better design. If nothing else, you might find this humorous. First of all, here''s the sample code (I apologize for not displaying it properly in that neat little window, but I have no idea how to do that):
// Begin code
// Percentage of deviation allowed from defined coordinates
struct VectorDev
{
char x;
char y;
char z;
};
class Particle
{
private:
int type;
typedef struct
{
// Array of possible origins
D3DVECTOR pos[100];
// Deviation from origin x, y and z component
VectorDev dev;
// Array index
int index;
} Origin;
typedef struct
{
// Array of possible destinations
D3DVECTOR pos[100];
// Deviation from destination x, y and z component
VectorDev dev;
// Array index
int index;
} Destination;
public:
// Constructor declaration
Particle(int initType = 1, ...?);
};
// End code
Ideally, I''d like to be able to access members of this class intuitively, (for me, anyways) like...
Particle *aParticle;
char destDeviationY;
aParticle->Origin.pos.x = (D3DVALUE)5.5;
deviationX = aParticle->Destination.dev.y;
The problem is how to write the class constructor when it comes to the nested structures. Granted, I could redesign the class so that there are no nested structures. Instead of using aParticle->Destination.dev.y I''d use aParticle->destDevY, and have separate variables for every other combination as well. I''m stubborn, though, and I''d like to see if I could do it with nested structures instead.
Thanks for any help.
FYI, I just read the message board FAQ and now know how to include source code properly, but I can''t seem to edit my original message right now.
As for the constructors
As for the access method, erm, make them public?
Jans.
Oh, and can I say 'messy'? Thought not.
-----------------
Janucybermetaltvgothmogbunny
Edited by - Jansic on October 14, 2000 6:25:24 PM
Particle:: Particle(param1, param2):Origin(param1), Destination(param2){}
As for the access method, erm, make them public?
Jans.
Oh, and can I say 'messy'? Thought not.
-----------------
Janucybermetaltvgothmogbunny
Edited by - Jansic on October 14, 2000 6:25:24 PM
Since I get a database error every time I try to edit my original post, I''ll just re-post it properly since the code is difficult to read otherwise.
In striving to organize the members of my class to make them more intuitive when accessed later on, I seem to have encountered a small problem. Maybe I''m way off the mark and it simply can''t/shouldn''t be done, in which case I''d appreciate any suggestions for a better design. If nothing else, you might find this humorous. First of all, here''s the sample code:
The problem is how to write the class constructor when it comes to the nested structures. Granted, I could redesign the class so that there are no nested structures. Instead of using aParticle->Destination.dev.y I''d use aParticle->destDevY, and have separate variables for every other combination as well. I''m stubborn, though, and I''d like to see if I could do it with nested structures instead.
Thanks for any help.
In striving to organize the members of my class to make them more intuitive when accessed later on, I seem to have encountered a small problem. Maybe I''m way off the mark and it simply can''t/shouldn''t be done, in which case I''d appreciate any suggestions for a better design. If nothing else, you might find this humorous. First of all, here''s the sample code:
// Percentage of deviation allowed from defined coordinatesstruct VectorDev{ char x; char y; char z;};class Particle{ private: int type; typedef struct { // Array of possible origins D3DVECTOR pos[100]; // Deviation from origin x, y and z component VectorDev dev; // Array index int index; } Origin; typedef struct { // Array of possible destinations D3DVECTOR pos[100]; // Deviation from destination x, y and z component VectorDev dev; // Array index int index; } Destination; public: // Constructor declaration Particle(int initType = 1, ...?);};[/source]Ideally, I''d like to be able to access members of this class intuitively, (for me, anyways) like...[source]Particle *aParticle;char destDeviationY;aParticle->Origin.pos.x = (D3DVALUE)5.5;deviationX = aParticle->Destination.dev.y;
The problem is how to write the class constructor when it comes to the nested structures. Granted, I could redesign the class so that there are no nested structures. Instead of using aParticle->Destination.dev.y I''d use aParticle->destDevY, and have separate variables for every other combination as well. I''m stubborn, though, and I''d like to see if I could do it with nested structures instead.
Thanks for any help.
October 14, 2000 05:37 PM
Thanks for the help, Jansic. I vaguely remember coming across that type of constructor code while I was sifting through the MSDN Library, but at the time I thought it didn''t apply to my situation. I''ll see if I can dig it up again to get more detailed information.
As for those private member variables, yes, I realize my sample code wouldn''t actually work unless they were public. In my real code I use public member functions to access them.
And yes, it is messy. My second attempt at posting the code yielded better results, although it would seem that the message board system doesn''t support two separate code windows in a single post. Oh well.
Thanks again.
As for those private member variables, yes, I realize my sample code wouldn''t actually work unless they were public. In my real code I use public member functions to access them.
And yes, it is messy. My second attempt at posting the code yielded better results, although it would seem that the message board system doesn''t support two separate code windows in a single post. Oh well.
Thanks again.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement