How to set data with 0 in C++? -
this question has answer here:
- initializing object zeroes 12 answers
in c set data 0 memset()
function (not initialization).
my data changed method , want reuse , want set 0 before reusing
are there way set data 0 in c++ other memset()
?
class myclass : public namespace::parentclass { private: struct mystruct data public: void method(); }; void myclass::method() { memset(&data, 0, sizeof(data)); // it's c way. there way in c++ }
in c++ invoke constructor of object, or initialiser primitive constructor-less objects.
re-initialisation should happen (don’t reuse variables, create new ones! makes program flow clearer) – but when need can re-assign new object:
data = mystruct();
Comments
Post a Comment