如何在C++中初始化指向结构的指针
How to initialize a pointer to a structure in C++?
这是class A
中struct structure
定义的结构。 Class B
嵌套在 Class A
中。
class A
{
public:
struct structure // the structure I need
{
std::vector <std::vector <float>> Input;
std::vector <int> Output;
float ft;
B* bb;
};
private:
B b;
structure* pStruct;
};
现在我想在使用它之前初始化指针pStruct
。
例如,我使用 pStruct->Output.push_back()
.
例如,您可以在类的默认构造函数中初始化指针。 类似的东西
class B {};
class A
{
public:
A() : b(), pStruct( new structure() ) { pStruct->bb = &b; }
struct structure // the structure I need
{
std::vector <std::vector <float>> Input;
std::vector <int> Output;
float ft;
B* bb;
};
private:
B b;
structure* pStruct;
};
相关文章:
- 如何在 C# 中映射双 C 结构指针?
- C++:映射结构中的结构指针
- C++:添加新结构时,结构指针向量中的所有元素都会更新
- 类的静态结构指针声明在C++
- 在两个.cpp文件之间定义全局类/结构指针
- 返回对常量结构(指针类型)成员的引用:明显的左值到右值转换
- 是否可以将无符号字符数组reinterpret_cast到仅包含C++中无符号字符成员的结构指针
- 如何在地图中使用结构指针
- 结构指针在"新"调用上给出已分配的地址?
- 铸造结构指针指向C 的工会指针
- c++ 结构指针在初始化为 NULL 时无法读取内存
- 函数中的结构指针的地址为0x1
- C 用结构指针初始化结构
- C 结构指针铸成数组Interop C#
- 方法中不允许访问结构指针
- 如何打印出结构指针
- MPI_Op_create:候选功能不可行.自定义结构指针不能解释为空指针
- 尝试将结构指针传递给类时出错
- 初始化结构指针的值
- 使用 pybind11 将自定义结构(指针向量)从 C++ 传递到 python 的方法是什么?