I'd use vector any time rather that CArray, reason pretty much same as BoulderBum mention, but also that I think it is easier to use.
Example:
{
std::vector<char> myString; // A string
myString.reserve(someSize+1); // Allocate space
char* sz = &myString.front(); // Now I can treat it like a simple char*
SomeReadStringFunction(sz, someSize);
}
If SomeReadStringFunction throws an exception myString will be deallocated properly with the vector's destructor,
----------
MFC has some nice portions, however I thing the design of its collection classes (CArray, CMapStringToString etc) is really terrible and un-flexible.
Also, MFC was invented before STL was part of C++ (that's probaly why we things such as CArray), so it is only "natural" that the STL is better...hmmm...well it is anyway
It is not only an issue of being portable (the windows based market is big enough for my needs anyway), but also to be generic. You can use STL's collaction classes for just about anything, while MFC's are resticted to (or designed for anyway) MFC stuff.
------
Hungarian notation? Brrrrrrr.
Hungarian notation is absolutely the WORST thing you can do to your code. There is no reason to code in type info in a variable name in C++. It was "invented" for cobol which is a totally different language.
Using prefix m for members, s for static members (and in theory g for glabal if we'd have one but we dont ;-) ) is sufficient.
1) What if you change from vector to, say, list? You'd then have to rename all variables using it. A task that will not improve the quality of you code one single bit. Or if you change from a pointer to a reference, or change from a pointer to an auto_ptr, of from a char* to a CString or std::string...
2) You can (or should be able to) fairly quickly decide what class some variable is:
2.1) Either it is a member (prefixed with an m)- then you can look in the class header
2.2) Or it is a local variable then it is also quite trivial since with C++ you define variables at the point where they are needed.
2.3) Or it is an in-parameter to a function which also its quite trivial to see the header of. If the function is so big you find it troublesome to find its header you probably have a problam with your design. A function should really do only one thing and do it good.
2.4) Global variables are BAD, so they are not an issue.
Or to put it like this:
If you find it troublesome to determine the type of a particular variable you probably as a design problem on a larger scale.
I must say I find at absolutely terrible to use Hungarian notation, especaially in a framework such as MFC (Microsoft has leared some and the naming guidelines for .net is clearly not Hungarian notation)
>For example, which of the following be correct (or none of them):
My answer is none.
1) No hungarian notation (see reason above)
2) vector instead of CArray (see reason above)
3) "Values" isn't a good name (I think) since it doesnt say what the variable really is. But since I don't really know, perhaps it is the perfect name. If so i'd call it:
std::vector<double, double> mValues;
/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.