开发者

how to Solve the error C2205(cannot initialize extern variables with block scope)

开发者 https://www.devze.com 2023-03-24 00:01 出处:网络
int inc(int a) { return (++a); } int Multi (int *a, int *b, int *c) { return (*c = *a**b); } typedefint(FUNC1) (int in);
int inc(int a)
{
    return (++a);
}
int Multi (int *a, int *b, int *c)
{
    return (*c = *a**b);
}


typedef  int(FUNC1) (int in);
typedef  int(FUNC2) (int *, int *, int *);

void Show (FUNC2 fun, int arg1, int *arg2)
{
    FUNC1 p = &inc; //this sentence can't access a pointer of a function
    int temp = p(arg1);
    fun (&temp, &arg1, arg2);
    cout<<(*arg2)<<endl;
}

int _tmain(int argc, 开发者_JAVA百科_TCHAR* argv[])
{
    int a;
    Show(Multi,10,&a);
    return 0;
}


You have declared your function pointer typedefs wrong. Try this:

typedef  int(*FUNC1) (int);
typedef  int(*FUNC2) (int *, int *, int *);
0

精彩评论

暂无评论...
验证码 换一张
取 消