c++ - 对函数的 decltype 感到沮丧

标签 c++ function typetraits

我现在正在为一些 Windows 库函数编写包装器,因此我需要提取它们的原型(prototype)并使用修改后的原型(prototype)编写一个新的包装器。例如:函数

int recv(SOCKET, char*, int, int)

将由

包裹
recv_wrapper(SOCKET, char*, int, int, THREADID)

为了避免错误,我写了一个包装器模板:

template <typename F> struct wrapper;

template <typename R, typename T1, typename T2, typename T3, typename T4>
struct wrapper<R(T1,T2,T3,T4)> 
{
  typedef R result_type;
  typedef R (type)(T1,T2,T3,T4,THREADID);
};

然后下面的包装类型有效:

typedef int recv_t(SOCKET,char*,int,int);
typedef wrapper<recv_t>::type recv_wrapper_t;

但我想进一步使用 decltype 来自动获取 recv 的类型:

typedef decltype(recv) recv_t;
typedef wrapper<recv_t>::type recv_wrapper_t;

但这不起作用,我尝试了几种方法来修改它,但我总是从 VS2010 编译器中得到错误:

error C2027: use of undefined type 'wrapper<F>'
with
        [
            F=int (SOCKET,char *,int,int)
        ]

error C2146: syntax error : missing ';' before identifier 'recv_wrapper_t'

我对此感到非常沮丧,因为这里的 F 只不过是明确定义的 recv_t:

typedef int recv_t(SOCKET,char*,int,int);

但是当用decltype自动获取时,它就不再起作用了。

非常感谢您的考虑。

注意我已经按照 n.m. 的建议修复了一个拼写错误;但这仍然不起作用。

最佳答案

template <typename F> wrapper;是无效的。你是说 template <typename F> struct wrapper; ?如果你解决了这个问题,明显的语法就可以工作了:

typedef wrapper<decltype(recv)>::type recv_wrapper_t;

关于c++ - 对函数的 decltype 感到沮丧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22514611/

相关文章:

c++ - 为什么不采用非类型偏特化元组?

c++ - 为什么 [std::is_move_assignable] 的行为不如预期?

c++ - 如何检查类型是否是 C++ 中模板类的类型参数?

c++ - 图像识别特征金字塔有多少步?

c++ - 在eclipse中隐藏控制台

arrays - 在 MATLAB 中将函数分布在数组的单个维度上?

C++ 如何在包含两个变量的结构中将不同数量的值存储到我的变量中?

c++ - 为什么 Microsoft Visual Studio 找不到 <stdint.h>?

c++ - gcc 4.4 与 gcc >4.4 中的默认链接模型

c++ - 从文本文件中的值中减去,然后输出计算 (C++)