In regards to vectors vs. dynamically allocated arrays I think arrays can be more efficient + less memory consumed than vectors, which may contain stuff you don't want to use anyways.. Plus you can memset 50 entries in an array to zero much quicker than going through each vector entry one by one plus other stuff. Though don't quote me on this stuff . (If you want simplicity vectors would be a great choice and any extra overhead I can't imagine would hurt your program. Not like your building a game or something intensive..)
---------------------------------------------
In regards to the initial post:
If your profiles are not pointers then yes a default constructor will be called when you create a multiprofile class, which would waste memory if you only decided to use 1 or 2 of the profiles like you mentioned..
If the max # of profiles is 3 then sure I believe your code is perfectly fine, but if there can be many profiles or perhaps you may want many down the road.. In order to make you class more ambigious and thus reusable for many different applications you might want to use a linked list structure to store profiles instead of later typing:
Code:
Profile* _profile1;
Profile* _profile2;
Profile* _profile3;
Profile* _profile4;
Profile* _profile5;
Profile* _profile6;
Obviously this could get messy while:
Code:
struct profileEntry
{
Profile *profile; // This could be a pointer or just a regular variable if you want.
profileEntry *nextEntry;
// add more stuff if yah want like:
// bool isLoaded;
// int profileID;
// string profileName; etc;
}
class MultiProfile
{
private:
profileEntry *profiles;
public:
MultiProfile( );
~MultiProfile( );
bool CreateProfile( int profilenumber, int numalts, double* alts, double* profile );
bool isLoaded(int profileNum);
};
bool MultiProfile::isLoaded(int profileNum)
{
profileEntry *iterator = profiles;
for(int i=0; i < profileNum; i++)
{
if(iterator == NULL) // Profile doesn't exist.
return false;
iterator = iterator->nextEntry; // Move to next entry in our profile list.
}
return true; // Profile exists.
}
I'm not sure if your familiar with linked lists, but this way would make your code more reusable for various scenarios. There is no profile limit just like the vector scenario, but is customized to your personal needs. You can store various information to accompany each profile in the profileEntry nodes if you want. And last it greatly reduces your variable list and clean-up problems in your destructor as you can iterate through each entry in the list rather than individually cleaning up profile_1; profile_2; etc.
ex:
is better than
Code:
int arrayItem1;
int arrayItem2;
int arrayItem3;
int arrayItem4;
...
int arrayItem50;
Just my opinions, but otherwise your code is fine as long as you are careful with passing your pointers double* alts, double* profile so you don't get memory leaks or more likely fatal program crashes in your profile deconstructor, which really chapped my ass until I figured what the problem was.
Good luck.