【发布时间】:2017-09-14 17:47:40
【问题描述】:
我试过memset喜欢
struct TreeNode {
bool exist;
bool word_ending;
TreeNode* branches[3];
TreeNode(): exist(true), word_ending(false) {
memset(branches, NULL, sizeof(branches));
}
};
但出现警告
warning: implicit conversion of NULL constant to 'int' [-Wnull-conversion]
memset(branches, NULL, sizeof(branches));
~~~~~~ ^~~~
0
1 warning generated.
还有其他方法可以初始化指向NULL的指针数组吗?
【问题讨论】:
-
TreeNode* branches[3] = {};在声明中。 -
NULL不等于0吗?
-
如果您在源代码中将 NULL 更改为 0,它将正常编译。但只要按照 NathanOliver 的建议去做。
标签: c++ arrays constructor initialization