我的错误在哪里? [英] where is my mistake ?

查看:114
本文介绍了我的错误在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre>#include <iostream>
using namespace std;

typedef void (*PFN)();

class A
{
public:
    void foo()
    {
        run(func);
    }

private:
    void run(PFN pfn1)
    {
        pfn1();
    }

    void func()
    {
        printf("run ");
    }
};

int main()
{
    A a;
    a.foo();

    system("pause");
    return 0;
}






在调试以下错误时显示:
错误C3867:``A :: func'':函数调用缺少参数列表;使用``& A :: func''创建指向成员的指针






while debuging following error shows:
error C3867: ''A::func'': function call missing argument list; use ''&A::func'' to create a pointer to member

推荐答案

已读取 ^ ].

看看你是否无法自救. :)
Have a read of this[^].

See if you can''t help yourself. :)


制作
void func()
{
    printf("run ");
}


进入关注静态成员函数


into the follow static member function

// static member Pointer
static void func()
{
    printf("run ");
}



而且您的语法应该正确

或对于成员函数指针,请尝试此



And your syntax should be correct

or for a member function pointer try this

#include <iostream>
// Example Member function pointer
using namespace std;
class A;
typedef void (A::*PFN)();
class A
{
public:
    void foo()
    {
        run(&A::func);
    }
private:
    void run(PFN pfn1)
    {
        ((*this).*pfn1)();
    }
    void func()
    {
        printf("run ");
    }
};


这篇关于我的错误在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆