我如何获取函数指针到模板类的模板方法

发布于 2025-02-08 21:04:31 字数 782 浏览 3 评论 0原文

模板类

template <typename ... _AttributeExtensions>
class SomeServiceProxy
    : virtual public SomeService,
      virtual public SomeServiceProxyBase,
      virtual public _AttributeExtensions... {

我有一个具有以下方法的

template <typename ... _AttributeExtensions>
void SomeServiceProxy<_AttributeExtensions...>::subscribeSomething(CommonAPI::CallStatus &_internalCallStatus, DataTypes::OperationStatus &_operationStatus, const CommonAPI::CallInfo *_info) {
    delegate_->subscribeSomething(_internalCallStatus, _operationStatus, _info);
}

:我正在尝试什么,但是不允许合格的名称:

typedef ( DataTypes::OperationStatus) (SomeServiceProxy::*subscribeCall) (void);

有什么方法可以获取该方法的函数指针?

I have a template class

template <typename ... _AttributeExtensions>
class SomeServiceProxy
    : virtual public SomeService,
      virtual public SomeServiceProxyBase,
      virtual public _AttributeExtensions... {

which has the following method:

template <typename ... _AttributeExtensions>
void SomeServiceProxy<_AttributeExtensions...>::subscribeSomething(CommonAPI::CallStatus &_internalCallStatus, DataTypes::OperationStatus &_operationStatus, const CommonAPI::CallInfo *_info) {
    delegate_->subscribeSomething(_internalCallStatus, _operationStatus, _info);
}

What I am trying, but qualified name is not allowed :

typedef ( DataTypes::OperationStatus) (SomeServiceProxy::*subscribeCall) (void);

Is there any way to get a function pointer to this method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山有枢 2025-02-15 21:04:32

您也需要为您的会员功能指针制作模板别名。
使用“使用”代替Typedef可以使您这样做。

template<typename... extensions>
class SomeServiceProxy
{
public:
    void DoSomething() {};
};

template<typename... extensions>
using DoSomethingFnPtr = void (SomeServiceProxy<extensions...>::*)();

int main()
{
    SomeServiceProxy<int, int> proxy;
    DoSomethingFnPtr<int,int> memfnptr = &SomeServiceProxy<int, int>::DoSomething;

    return 0;
}

You will need to make a template alias for your member function pointer too.
Using "using" instead of typedef allows you to do that.

template<typename... extensions>
class SomeServiceProxy
{
public:
    void DoSomething() {};
};

template<typename... extensions>
using DoSomethingFnPtr = void (SomeServiceProxy<extensions...>::*)();

int main()
{
    SomeServiceProxy<int, int> proxy;
    DoSomethingFnPtr<int,int> memfnptr = &SomeServiceProxy<int, int>::DoSomething;

    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文