qmech
January 30th, 2008, 07:07 PM
First timer poster...
I'm having a bit of a problem formulating my question, so please bare with me...
I've done a lot of programming in a lot of languages, from obscure to common - but somehow I always avoided C and C++. Well, I recently decided to fix this glaring fault in my upbringing and decided to do my next project in C++ (I have done some C programming, but not a lot).
I'm *trying* to do The Right Thing and not think in terms of the languages I know and simply "translating" that into C++. This would be especially bad considering that I've not done a lot of OOP...
My problem, then, is this:
I want to describe a bunch of "nodes" connected in some manner (a mesh). So, trying to think in OO terms, the right thing to do would seem to be to make a node class (and a mesh class, in which the node appears). An instance of a node needs to contain, among other things, information about the other nodes it is connected to.
A node can be connected to any number of other nodes (all, some or none), so the question is how is this property best described in the node class?
My simple non-C++ way of thinking would just use a dynamic array to store this information. IOW something along the lines of:
class MyNodeClass {
public:
int connections[];
};
where the connections array would just contain a list of all the node id's, that the node is connected to.
(I know I shouldn't use the code as above, it's there to explain my line of thinking)
What's The Right Way of implementing this in C++? Do I dynamically allocate memory for array on creation (I would rather avoid STL and similar solutions). Should I look at using linked lists? Am I just being completely dense? (always a possibility)
Any insight would be greatly appreciated.
I'm having a bit of a problem formulating my question, so please bare with me...
I've done a lot of programming in a lot of languages, from obscure to common - but somehow I always avoided C and C++. Well, I recently decided to fix this glaring fault in my upbringing and decided to do my next project in C++ (I have done some C programming, but not a lot).
I'm *trying* to do The Right Thing and not think in terms of the languages I know and simply "translating" that into C++. This would be especially bad considering that I've not done a lot of OOP...
My problem, then, is this:
I want to describe a bunch of "nodes" connected in some manner (a mesh). So, trying to think in OO terms, the right thing to do would seem to be to make a node class (and a mesh class, in which the node appears). An instance of a node needs to contain, among other things, information about the other nodes it is connected to.
A node can be connected to any number of other nodes (all, some or none), so the question is how is this property best described in the node class?
My simple non-C++ way of thinking would just use a dynamic array to store this information. IOW something along the lines of:
class MyNodeClass {
public:
int connections[];
};
where the connections array would just contain a list of all the node id's, that the node is connected to.
(I know I shouldn't use the code as above, it's there to explain my line of thinking)
What's The Right Way of implementing this in C++? Do I dynamically allocate memory for array on creation (I would rather avoid STL and similar solutions). Should I look at using linked lists? Am I just being completely dense? (always a possibility)
Any insight would be greatly appreciated.