C++11 这行代码有什么作用

C++11 What does this line of code do?

本文关键字:什么 作用 代码 C++11      更新时间:2023-10-16

我正在浏览 Nano-signal-slot 源代码,希望它可以帮助我使用 C++11 将信号和时隙功能实现到我的应用程序中,我遇到了一部分我以前从未见过的代码。

部分代码:

/* ... */
template <typename Re_t> class function;
template <typename Re_t, typename... Args>
class function<Re_t(Args...)>
{
    void *m_this_ptr;
    Re_t(*m_stub_ptr)(void*, Args...);
/* ... */

更具体地说:

class function<Re_t(Args...)>

类名后面做什么?

class function<Re_t(Args...)>定义了模板化类function<T>的部分专用化。基本上,这允许您以函子的形式编写专用化,例如:

function<int(double,unsigned)> foo = ...

请注意,由于使用了 Args...,您可以拥有可变数量的参数。