在课堂内写结构

Writing struct inside a class

本文关键字:结构 课堂      更新时间:2023-10-16

这是关于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的定义未公开。