gpt4 book ai didi

c++ - 类中的 VC++ 函数指针

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:58 26 4
gpt4 key购买 nike

LASReader.h

class LASReader
{

public:

LASReader();
~LASReader();

Point3 (LASReader::*GetPoint)();

private:

Point3 GetPointF0();
Point3 GetPointF1();
Point3 GetPointF2();
Point3 GetPointF3();
Point3 GetPointF4();
Point3 GetPointF5();
};

LASReader.cpp

switch (m_header.PointDataFormat)
{
case 0:
m_formatSize = sizeof(LASPOINTF0);
GetPoint = &LASReader::GetPointF0;
break;
case 1:
m_formatSize = sizeof(LASPOINTF1);
GetPoint = &LASReader::GetPointF1;
break;
case 2:
m_formatSize = sizeof(LASPOINTF2);
GetPoint = &LASReader::GetPointF2;
break;
case 3:
m_formatSize = sizeof(LASPOINTF3);
GetPoint = &LASReader::GetPointF3;
break;
case 4:
m_formatSize = sizeof(LASPOINTF4);
GetPoint = &LASReader::GetPointF4;
break;
case 5:
m_formatSize = sizeof(LASPOINTF5);
GetPoint = &LASReader::GetPointF5;
break;
default:
break; // Unknown Point Data Format
}

主要.cpp

Point3 p = reader->GetPoint;

“错误 C2440:‘初始化’:无法从‘Point3 (__cdecl LASReader::* )(void)’转换为‘Point3’”

当我使用手镯时

Point3 p = reader->GetPoint();

“错误 C2064:项未计算为采用 0 个参数的函数”

我做错了什么?

最佳答案

您需要使用(reader->*reader->GetPoint)() 来调用它。参见 How to invoke pointer to member function when it's a class data member?

关于c++ - 类中的 VC++ 函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17799868/

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