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:
Obviously this could get messy while:
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.
Profile *profile; // This could be a pointer or just a regular variable if you want.
// add more stuff if yah want like:
// bool isLoaded;
// int profileID;
// string profileName; etc;
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.
iterator = iterator->nextEntry; // Move to next entry in our profile list.
return true; // Profile exists.
is better than
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.