C struct as class member variable, zero "init" data in class constructor
Hello,
So, at my work we use a static analysis tool and it is pointing out some uninitialized variables. One of which is a class member variable which is a C struct. Now, that variable is already declared in the header file for the class.
Currently in the class constructor I am doing:
Code:
memset( &thestruct, 0, sizeof( thestruct ) );
Is there a C++ way to do this? I Googled this but all I really found was:
Re: C struct as class member variable, zero "init" data in class constructor
In C++ you usually implement a (default and probably some other) ctor(s) in your structure and do the default and other initialization within the ctor(s)
Re: C struct as class member variable, zero "init" data in class constructor
Try adding a constructor to the struct. If you compile with C++ the compilation will succeed but in C it will not.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Bookmarks