Perhaps you can help me finding a way to make a shallow memberwise copy of any element of a class in one go. My question is the following. Given a class like:
class TestClass
{
public:
double b;
double ar[3];
};
Is there a way to make this copy using the default assignment operator inside
my own assignment operator? I know the C++ compiler knows how to do it since
by default working.
In my real C++ class I have many variables and static arrays (>50) in the class and only a couple of dynamic array allocations (I need the = operator) and then I am forced to copy member by member all
the static variables in the = operator.
At the end is crazy, if tomorrow I add a new variable to the class and I forget to include it in the assignement operator I will get into trouble.
In my real C++ class I have many variables and static arrays (>50) in the class and only a couple of dynamic array allocations (I need the = operator) and then I am forced to copy member by member all
the static variables in the = operator.
If member variables of your class are declared static, then you should not have to copy them between instances of your class. But I have a feeling that you already know this and I'm just being an idiot, so would you mind rephrasing your question?
Excuse me, I did not meant static array but regular arrays (eg double v[5]). My question is whether may I use the intelligence of the default assignment operator that is working perfectly when I create my own assignment operator and take care only of the couple of dynamic arrays I use. I do not want to write something like:
If you broke this up into two classes with the regular (non-dynamic) variables in a parent class you should be able to use the default assignment operator from that parent class to fill out those variables via a base class pointer to the derived one.