簡體   English   中英

錯誤C2228:'。Alloc'的左邊必須有class / struct / union

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

我有一個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   

語法是否正確? 為什么要上課?什么是正確的方法?

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

撇開這會調用未定義的行為 ,因為lBuffer未初始化,你想要:

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

因為lBuffer是一個指針。

lBufferPvBuffer* ,你需要創建和尊重:

lBuffer = new PvBuffer()
lBuffer->Alloc(....);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM