Visual Studio 2012中的函数指针 [英] Function pointer in Visual Studio 2012

查看:99
本文介绍了Visual Studio 2012中的函数指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请向我解释我哪里错了.我想使用函数指针在多个编码实用程序之间切换.我这样声明

Please explain me where I am wrong. I want to switch between several encoding utilities using pointer to function. I declare it like

int (*enc_routine)();

后来我切换了类似的编码实用程序

Later I switch coding utilities like

enc_routine = g723_24_encoder;

其中实用程序本身类似于

where utility by itself is something like

extern int g723_24_encoder(
    int sample,
    int in_coding,
    struct g72x_state *state_ptr);

在Linux上,一切都很不错,但是现在我在Visual Studio 2012上,它说:

Everything was cute and fine on Linux, but now I am on Visual Studio 2012 and it says:

不能将类型为"int(*)(int sample,int in_coding,g72x_state * state_ptr)"的值分配给类型为"int(*)()"的实体

a value of type "int (*)(int sample, int in_coding, g72x_state *state_ptr)" cannot be assigned to an entity of type "int (*)()"

感谢您的帮助(如果有的话)!

Thank you for help (if any)!

推荐答案

您需要为函数指针声明参数.您不能声明它不带任何参数并将其设置为等于需要3个参数的函数.我很震惊它可以在linux上运行.

You need to declare the parameters for your function pointer. You can't declare it to take no parameters and set it equal to a function that requires 3 parameters. I'm shocked it worked on linux.

这篇关于Visual Studio 2012中的函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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