是否可以在模板中键入指向外部"C"函数类型的指针? [英] Is it possible to typedef a pointer-to-extern-"C"-function type within a template?

查看:91
本文介绍了是否可以在模板中键入指向外部"C"函数类型的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模板中添加公共typedef,以指向使用"C"语言链接的函数接受一参数的指针.

I want to add a public typedef to a template for a pointer to a function-taking-one-argument that uses "C" language linkage.

我尝试过:

extern "C" {
    template <typename return_t_, typename arg1_t_>
    struct test
    {
        typedef return_t_ (*C_fun1_t)(arg1_t_);
    };
}

并且:

template <typename return_t_, typename arg1_t_>
struct test
{
    extern "C" {
        typedef return_t_ (*C_fun1_t)(arg1_t_);
    }
};

并且:

template <typename return_t_, typename arg1_t_>
struct test
{
    extern "C" typedef return_t_ (*C_fun1_t)(arg1_t_);
};

没有成功.

我要实现的目标是可能的吗?

Is what I am trying to accomplish possible?

推荐答案

C ++ 03,第7.5p4节:

C++03, §7.5p4:

链接规范应仅在命名空间范围内发生. …类成员名称和类成员函数的成员函数类型将忽略C语言链接.

A linkage-specification shall occur only in namespace scope. … A C language linkage is ignored for the names of class members and the member function type of class member functions.

不幸的是,您在当前的C ++中根本无法做到这一点.该文本在最新的C ++ 0x草案中未更改,但"template typedefs"也许可以完成.

Unfortunately, you simply can't do this in current C++. This text is unchanged in the latest C++0x draft, but "template typedefs" may be able to accomplish it.

这篇关于是否可以在模板中键入指向外部"C"函数类型的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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