gpt4 book ai didi

c++ - 错误 C2228 : left of '.Alloc' must have class/struct/union

转载 作者:行者123 更新时间:2023-11-30 02:03:51 27 4
gpt4 key购买 nike

我有一个 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 函数(参见类(class)中的最后一个函数)。所以我这样写程序:

 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是一个指针。

关于c++ - 错误 C2228 : left of '.Alloc' must have class/struct/union,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11331910/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com