我有三个班,TImageProcessingEngine
,TImage
和TProcessing
访问来自不同类的对象 - 设计
TImageProcessingEngine
是我使用的暴露我的所有方法在世界上独一无二。
TImage
是我打算使用通用图像读取和图像写入功能。
TProcessing
包含将执行成像操作的方法。
class TImageProcessingEngine
{
public:
TImage* mpImageProcessingEngine;
};
class TImage
{
public:
int ReadImage();
int WriteImage();
private:
//a two dimensional array holding the pixel values
tImageMatrix* mpImageMatrix;
};
class TProcessing
{
public:
int ConvertToBinary();
int ConvertToGrayScale();
};
我的问题是如何访问对象mpImageMatrix
在TProcessing
类?所以,我调用应用程序可以使用下面的
TImageProcessingEngine* vEngine = new TImageProcessingEngine;
//Converts an input gray scsale image to binary image
vEngine->ReadImage().ConvertToBinary();
//Write the converted image to disk
vEngine->WriteImage();
delete vEngine;
vEngine = NULL;
//During this whole processing internally,
//the image is read in to `mpImageMatrix`
//and will also be holding the binarised image data,
//till writing the image to disk.
或者你推荐任何其他的方法来我的一流的设计?
您应该尝试使用较少的'new'和较少的指针,并利用为值提供的自动清理。在删除它之后,设置一个指向'null'的指针也是不好的做法,它会隐藏错误。 – 2010-09-01 08:56:20
删除'隐藏错误'后将指针设置为NULL?恰恰相反,将其设置为NULL可确保在删除后指针的任何访问都会引发异常(在大多数C++编译器上授予:在所有用于x86的C++编译器上) – 2010-09-13 16:23:52