【发布时间】: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
我最近看到了这个:
template <class U> struct ST
{
...
};
template <class U, class V>
struct ST<U V::*>
{
...
};
我假设第二个模板是第一个模板的特化。
但是U V::* 的语义是什么???
【问题讨论】:
标签: c++ templates syntax semantics
这意味着“指向类 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
【讨论】: