2017-02-18 26 views
0

这是关于C++的一般问题。我试图制作一个Camera类,它将包含包含各种相机属性的私有成员结构。在类中写入struct

Class Camere 
{ 
public: 


int read_input_image(properties &c, const char *file_name);  

private: 
struct properties 
{ 
double* input_image; 
double* output_image; 
---- 
---- 
} 
} 

properties 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.另一个问题是我应该如何删除与类内的结构相关的指针,我是否需要删除input_image指针。

+0

将Class字改为小写字母,并修正Camere或Camera –

回答

0

我怎么会得到访问结构

的结构有没有私有成员的私有成员,所有成员都是公开的,因为结构的缺省访问是公共的。

,我需要删除input_image指针

是的,你需要delete input_image,因为它指向new版内存。

+0

int read_input_image(properties&c,const char * file_name);显示错误,我将如何使用这个结构来私下调用函数。 – Angelina

0

它不是你的结构成员是私有的,而是结构本身的定义。

由于成员不是私人成员(除非另有说明,结构的成员是公共的),您可以在任何已知struct properties的点上访问它们,在这种情况下只能在类Camere内部访问。 类别Camere之外,struct properties未知,因此无法访问。请注意,这不是因为任何“私人”成员(不是私人的),而是因为struct properties的定义没有公开。