c++ 代码细节问题记录
1 带指针的类,初始化构造函数需要手动设置nullptr
#include <iostream>
using namespace std;
class A {
public:
A() {};
A* next;
};
int main() {
A a;
cout<<(a.next == nullptr)<<endl;
return 0;
}
结果:
0
#include <iostream>
using namespace std;
class A {
public:
A() {};
A* next;
};
int main() {
A a;
cout<<(a.next == nullptr)<<endl;
return 0;
}
结果:
0