#operator= and MFC
2 messages in this thread
In the interest of good C++ practice I am coding my classes with copy
contructors and where appropriate overloaded assignment (operator=) functions.
Now I come accross the MFC defined classes (from which I inherit) and I find
that they dont in fact define copy contructors or even assingment functions.
So for example you cant do…
CObArray a;
CObArray b;
b = a;
Also in my assignment contructors I want to assign the inherited parts of the
object, ususally like this..
class MyClass : CObject {
…
}
MyClass& MyClass:operator=(MyClass& rhs)
{
CObject::=operator=(rhs);
…
return this*;
}
Have I got this all wrong (and in this case can you tell me why) or is the MFC
not a good example of C++ practices??
Brad Baker
Sterling Software
Sydney, Australia
Well Brad, yes and no. Depends on how pure you are. The fact that CObList
doesn't have an '=' opererator doesn't bother me much. First off, I don't copy
entire lists very often. Second, if I did want to copy a list, would I want to
copy just the pointers to the data held in the list, or also copy all the data
pointed to by elements in the list. It's a little too ambiguous to guess at.
Third, I can copy the pointers of a list with a single line of code (AddTail(),
AddHead() take CObList pointers as well as CObject pointers) anyway.
Now, if you want to talk about C++ purism, then I think the fact that VC++
doesn't support templates is far more annoying. The fact that we need a
CObList, a CPtrList, a CStringList, etc is simply out of date. Not to mention
the fact that the only types of containers are lists and arrays (no btrees,
stacks, queues, etc) unlike some other venders.
I, for one, am really hoping that VC++ version 2 addresses a lot of these
problems.
Chris