STL vector - structure's vector
Hi guys,
I have a structure and a vector to a structure.
Code:
struct myParams
{
double angleOX;
double angleOY;
double angleOZ;
double trOX;
double trOY;
double trOZ;
double bandHeight;
};
------------
------------
std::vector<myParams> m_c_Vector;
And I use it into a code like that:
Code:
m_c_Vector.clear();
myParams s_param;
int x = 0;
do {
x = fscanf(file_stream,"%lf\t%lf\t%lf", &s_param.angleOX, &s_param.angleOY, &s_param.angleOZ);
m_c_Vector.push_back(s_param);
} while (x != 0);
Finaly, I have a structure's vector with some valid values on this used members but, some members sets by default, unemployed.
As you can see in the last code section, I'm not using all the members the myParams structure (e.g. trOX, trOY, trOZ, bandHeight). At that moment, I don't need to use this structure's members, but perhaps in the future, I'll need it. I designed myStruct right on this ideea.
I'm asking if that kind of design and writing code it's better than the designing of a smaller structure with the moment necessary members?
Regards.
Re: [RESOLVED] STL vector - structure's vector
If you are not making the file (that you are using for input or output) accomodate the new variables that could be added now, then just adding them into the structure and hence the vector would not help much.
If the file has got those extra fields, then I don't think there's any problem keeping them in your struct as well (as long as you don't worry about that wasted memory).
Also, it would be better if you had overloads wherever such dependency is in your code. The code that is sensitive to the count of fields like the fscanf - should be wrapped into another function and should be overload - so that at a later point of time you could just turn a "switch" to use the other overload and things would be just fine. (Also, it gives you flexibility to "switch" back to older format). It will avoid re-work caused by such "switching".
Re: [RESOLVED] STL vector - structure's vector
Quote:
Originally Posted by exterminator
If you are not making the file (that you are using for input or output) accomodate the new variables that could be added now, then just adding them into the structure and hence the vector would not help much.
If the file has got those extra fields, then I don't think there's any problem keeping them in your struct as well (as long as you don't worry about that wasted memory).
Also, it would be better if you had overloads wherever such dependency is in your code. The code that is sensitive to the count of fields like the fscanf - should be wrapped into another function and should be overload - so that at a later point of time you could just turn a "switch" to use the other overload and things would be just fine. (Also, it gives you flexibility to "switch" back to older format). It will avoid re-work caused by such "switching".
First of all, thank you very much for your's complete explications.
I appreciate very much your's ideeas. It's a professional point of view and that's will be my point of view, too.
Kind regards.
Re: [RESOLVED] STL vector - structure's vector
[ merged threads ]
Regards,
Siddhartha
Re: [RESOLVED] STL vector - structure's vector
Quote:
Originally Posted by Siddhartha
[ merged threads ]
Regards,
Siddhartha
I don't know how... First, I was going to delete the thread from C++ forum, but I didn't find how...
Show me, how can I merge the thread.
Regards!
:)
Re: [RESOLVED] STL vector - structure's vector
Quote:
Originally Posted by Maximus_X
First, I was going to del the thread from C++ forum, but I didn't find how...
Just click the "Edit" button on the first post and you will find an option to delete that post. Deleting the first post will delete the thread.
(Please don't delete this thread - but, you can test the forum here!)
Quote:
Originally Posted by Maximus_X
Show me, how can I merge the thread.
Ah, as far as merging goes - you can ask me... :)
Re: [RESOLVED] STL vector - structure's vector
Quote:
Originally Posted by Siddhartha
Just click the "Edit" button on the first post and you will find an option to delete that post. Deleting the first post will delete the thread.
(Please don't delete this thread - but, you can test the forum
here!)
Thanks for that explication. Be sure that I'll never delete this thread.
I'm glad that I can start interesting and usedfull threads.
All the best! :thumb: