1

我有一个 SDK(GigE C++),它定义了一个像这样的类:

class PV_BUFFER_API PvBuffer
 {

public: 

 PvBuffer();
 virtual ~PvBuffer();
 PvPayloadType GetPayloadType() const;
 #ifndef PV_NODEPRECATED
 PvResult Alloc( PvUInt32 aSizeX, PvUInt32 aSizeY, PvPixelType aPixelType );
};

SDK的文档说:

 PvResult PvBuffer::Alloc  ( PvUInt32  aSizeX,  
 PvUInt32  aSizeY,  
 PvPixelType  aPixelType   
 )    

 Allocates memory for this PvBuffer. 

 Parameters:
 [in]  aSizeX  The width of the image, in pixels. See GetWidth.  
 [in]  aSizeY  The height of the image, in pixels. See GetHeight.  
 [in]  aPixelType  The GEV pixel type from which the pixel depth is extracted. For     
 supported pixel types, see PvPixelType.h. 

 Returns:
 Includes:
 PvResult::Code::OK 
 PvResult::Code::NOT_ENOUGH_MEMORY 

我想使用 Alloc 函数(参见类中的最后一个函数)。所以我写这样的程序:

 PvBuffer *lBuffer;  //Class name is PvBuffer
 PvResult lResult= lBuffer.Alloc( 1224, 1029,  PVPIXELMONO );

但它给出了错误,其中之一是:

error C2228: left of '.Alloc' must have class/struct/union   

语法正确吗?为什么要上课?正确的方法是什么?

4

2 回答 2

3
PvBuffer *lBuffer;  //Class name is PvBuffer
PvResult lResult= lBuffer.Alloc( 1224, 1029,  PVPIXELMONO );

撇开这会调用未定义的行为,因为lBuffer没有初始化,你想要:

PvResult lResult= lBuffer->Alloc( 1224, 1029,  PVPIXELMONO );

因为lBuffer是指针。

于 2012-07-04T15:28:52.133 回答
1

lBufferPvBuffer*,你需要创造和尊重:

lBuffer = new PvBuffer()
lBuffer->Alloc(....);
于 2012-07-04T15:29:21.253 回答