【问题标题】:error C2228: left of '.Alloc' must have class/struct/union错误 C2228:'.Alloc' 左侧必须有类/结构/联合
【发布时间】:2012-07-04 23:44:04
【问题描述】:

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

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

【问题讨论】:

    标签: c++ mfc


    【解决方案1】:
    PvBuffer *lBuffer;  //Class name is PvBuffer
    PvResult lResult= lBuffer.Alloc( 1224, 1029,  PVPIXELMONO );
    

    暂且不说这会调用未定义的行为,因为lBuffer 没有被初始化,你想要:

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

    因为lBuffer 是一个指针。

    【讨论】:

    • 这样做了,现在 Intellisense 正在报告:错误:没有重载函数“PvBuffer::Alloc”的实例与参数列表匹配...是因为我的参数错误吗?
    • @gpuguy 先编译。 Intellisense 不是编译器。
    • @gpuguy,这完全是一个不同的问题。 :)
    • @gpuguy 请发布一个新问题,不要放大已经回答的问题。
    【解决方案2】:

    lBufferPvBuffer*,你需要创建和遵守:

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

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      相关资源
      最近更新 更多