如何在 C++ 中的构造函数中正确实例化指针数组
how to properly instantiate an array of pointers in constructor in c++?
关于通过构造函数实例化数组的简单问题。我有一个指向类 x 的指针数组,我正在尝试通过构造函数将数组成员设置为 nullptr。
这是我的 y.h
#include <array>
#include "x.h"
class y
{
public:
static const size_t number = 20;
y();
private:
std::array<x*, number> arrayList;
};
这是我的Y.cpp
#include "y.h"
#include "x.h"
#include <array>
using namespace std;
y::y()
: arrayList(nullptr)
{
}
使用值初始化:
y::y()
: arrayList()
{
}
或
y::y()
: arrayList{}
{
}
相关文章:
- 为什么我们不在下面给出的代码中使用指针来实例化C++的实体对象?
- 为什么我不能引用指向实例化对象的函数的指针?
- 是否可以将指向未实例化的对象的指针用作C++中的变量?
- 为什么在使用指针时不采用类成员的默认值,而不是直接实例化对象时?
- 为共享指针C++单独实例化对象
- 为什么不能在实例化对基类的引用的同时实例化指向派生类的指针?
- 模板类实例化中的指针转换无效
- 实例化一个模板类,该类采用具有不同函数签名的构造函数中的函数指针
- 为什么当我在构造函数中创建线程时,实例化对象和对象的指针的行为不同
- make_pair并push_back基指针,并实例化基指针的向量
- 声明基类类型的指针,但随后通过指向子类来实例化它.这是良好的编程实践吗?
- 使用派生类实例化基类,而不在对象定义中使用指针
- (C++)用于实例化新对象并将其分配给指向相同对象类型的指针的 2D 向量的语法
- C 实例化对象,在没有指针的情况下,其他类构造函数中没有默认构造函数
- 如何在 C++ 中的构造函数中正确实例化指针数组
- 实例化指针从继承类函数
- 间接实例化指针
- 对在头文件中实例化指针感到困惑
- 无法在主窗口类中实例化指针
- 0xC00000005未实例化指针错误