我有一个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
语法是否正确?为什么要上课?什么是正确的方法?
答案 0 :(得分:3)
PvBuffer *lBuffer; //Class name is PvBuffer
PvResult lResult= lBuffer.Alloc( 1224, 1029, PVPIXELMONO );
除此之外,这会调用未定义的行为,因为lBuffer
未初始化,您需要:
PvResult lResult= lBuffer->Alloc( 1224, 1029, PVPIXELMONO );
因为lBuffer
是指针。
答案 1 :(得分:1)
lBuffer
是PvBuffer*
,您需要创建和参与:
lBuffer = new PvBuffer()
lBuffer->Alloc(....);