Is there a way to initialize all the data members of a class that has a user defined constructor?
class CTest
{
private:
int a = 0;
BYTE b; CHAR* c; int d; int e; int f; int g;
public:
CTest() b:(0)
{
c = 0;
}
};
Imagine my class has 100 data members, and I want to initialize them all to zero.
Doing it 1 by 1 is not optimal. The workaround I'm using right now is: I put all those 100 data members in a structure which is the base for my class
like
class : public base_with_all_members
and when I want to reset all the members I just do the following in the constructor or in a initialize()
function for example.
*dynamic_cast<base_with_all_members*>(this) = {};
Which does properly clears all members.