I never heard that this was possible, but I asked with the hope that this is possible.
For a class with many other member variables than this:
class A
{
public:
SomeOtherClass* s;
int i;
int j;
A() {}
A(const A& soc): s(soc.s->Clone()), i(soc.i), j(soc.j) {}
};
I always need to remember that if I add another variable to the class int k, I will also have to add it to the initialization list k(soc.k), and sometimes in the destructor. I had to add / remove member variables many times, and it is very unpleasant for me to forget about copying in the initialization list and much more often to find an omission during debugging.
So I wanted to know if there is syntax / logic through which I can find out a list of class member variables and their types so that I can possibly iterate over them and decide which ones need to be copied to ctor copies and which ones need to be deeply copy?
I donβt understand why the creators of C ++ could not include such a tool, since apart from the virtual members, the memory cells of the variables would be adjacent, and their types are also known. Even if they were external or virtual, the type and size will be known at runtime. It should not be?
source
share