在课堂内写结构
Writing struct inside a class
这是关于C 的一般问题。我正在尝试制作一个相机类,其中包含包含各种相机属性的私有成员结构。
Class Camere
{
public:
int read_input_image(properties &c, const char *file_name);
private:
struct properties
{
double* input_image;
double* output_image;
----
----
}
}
属性C;}
.cpp文件
int Camera :: read_input_image(properties &c, const char *file_name) {
if(c.input_image == 0) {
c.input_image = new uint8_image_t;
c.input_image->data = 0;
}
现在,1.我的问题是我如何获得结构的私人成员, 如果我想编写访问结构成员的函数。2.另一个问题是我应该如何删除与struct Inside Class相关的指针,我需要删除Input_image指针。
我将如何获得结构的私人成员
结构没有私人成员,其所有成员都是公开的,因为结构的默认访问是公开的。
我需要删除input_image指针
是的,您需要delete input_image
,因为它指向new
ED内存。
不是私有结构的成员,而是结构本身的定义。
由于成员不是私有的(除非另有指定,否则结构的成员是公共的),因此您可以在知道struct properties
的任何时候访问它们,在这种情况下,只有在Camere
类中。在Camere
类之外,struct properties
尚不清楚,无法访问。请注意,这不是因为任何"私人"成员(不是私有的),而是因为struct properties
的定义未公开。
相关文章:
- 如何循环打印顶点结构
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 预处理器:插入结构名称中的前一个行号
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 孤立代码块在结构中引发异常
- 有什么方法可以遍历结构吗
- 如何在 C# 中映射双 C 结构指针?
- 如何在C++中使用结构生成映射
- 无法将结构注册为增强几何体3D点
- 多成员Constexpr结构初始化
- C++将文本文件中的数据读取到结构数组中
- 如何重构类层次结构以避免菱形问题
- 如何在C++中序列化结构数据
- 如何在课堂上访问私有结构
- 在课堂内写结构
- 在课堂定义期间的结构初始化
- 如何在课堂内定义结构
- 实施:课堂上的私人结构
- 在课堂上做一个结构