Is member value in the class initialized when an object is created?

删除回忆录丶 提交于 2019-12-02 11:58:35

The table_ array will be uninitialized in your current design, just like if you say int n;. However, you can value-initialize the array (and thus zero-initialize each member) in the constructor:

struct hash_map
{
    hash_map()
    : table_()
    {
    }

    // ...
};

You have to set all pointers to NULL. You do not have to use a loop, you can call in the contructor :

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