How to zero array members when my compiler isn't standard conform

旧时模样 提交于 2019-12-01 19:06:17

I think you may use this:

TT() { std::fill(b, b + 8, char()); }

This way you will solve your problem while nothing is wrong with portability and standard conformance!

jcm

You may use fill_n like suggested in: C/C++ initialization of a normal array with one default value

If no fill_n is available, you can always use memset like:

TT() {memset(b, 0, sizeof b);}

I would like to append previous posts that if you are using a character array as a string then it is enough to write in the constructor

TT() { b[0] = '\0'; }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!