【问题标题】:Meaning of template syntax with scope qualifier具有范围限定符的模板语法的含义
【发布时间】:2013-03-25 19:28:10
【问题描述】:

我最近看到了这个:

template <class U> struct ST
{
...
};
template <class U, class V>
struct ST<U V::*>
{
...
};

我假设第二个模板是第一个模板的特化。

但是U V::* 的语义是什么???

【问题讨论】:

    标签: c++ templates syntax semantics


    【解决方案1】:

    这意味着“指向类 V 的成员的指针,其中成员的类型是 U”。例如,

    struct X
    {
        int x = 0;
    };
    
    // ...
    
    int X::*p = &X::x;     // <== Declares p as pointer-to-member
    
    ST<decltype(&X::x)> s; // <== Will instantiate your template specialization,
                           //     with U = int and V = X
    
    ST<int X::*> t;        // <== Will instantiate your template specialization,
                           //     with U = int and V = X
    

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2011-12-08
      • 2017-02-05
      相关资源
      最近更新 更多