gpt4 book ai didi

c++ - "unqualified-id"通过指针访问类成员时编译器错误

转载 作者:行者123 更新时间:2023-11-30 01:16:19 24 4
gpt4 key购买 nike

我目前正在开发一个用于我的几个程序的委托(delegate)类。我的松散函数代码有效,但我在绑定(bind)成员函数的代码中遇到编译器错误。编译错误内容为

error: expected unqualified-id before '(' token.

我看不出有任何理由会出现这种情况。我的代码,不包括编译良好的部分,如下所示:

template <typename T> class Delegate;

template <typename R, typename... Args>
class Delegate<R(Args)>
{
typedef void* InstancePtr;

//...

template <typename C, R (C::*classFunction)(Args...)>
static inline R MakeStubFunction(InstancePtr instance, Args... args)
{
// vvv error on this line vvv
return ( static_cast<C*>(instance)->(*classFunction) )(args...);
}

//...

};

谁能指出编译器错误的来源?为了将来能够解决此类问题,“unqualified-id”是什么意思?

最佳答案

去掉大括号,使用->*操作符:

return ( static_cast<C*>(instance)->*classFunction )(args...);

关于c++ - "unqualified-id"通过指针访问类成员时编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26832766/

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