gpt4 book ai didi

c++ - 返回指向类成员函数的指针

转载 作者:太空狗 更新时间:2023-10-29 21:01:00 25 4
gpt4 key购买 nike

下面的问题让我抓狂,虽然它看起来并不奇怪:

class Foo;

// This is the location of the first error code
// ↓
int (Foo::*)(int) getPointer()
{
return 0;
}

GCC 给我:

error: expected unqualified-id before ')' token
error: expected initializer before 'getPointer'

PS: 我用 -std=c++11 编译

最佳答案

int ( Foo::* ( getPointer() ) )();

话虽如此,请记住您可以使用 typedef。对于函数指针,它通常会提高整体的可读性:

typedef int ( Foo::* TypeName )();

TypeName getPointer();

关于c++ - 返回指向类成员函数的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19962091/

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