C++ 带范围限定符的模板语法的含义
我最近看到:C++ 带范围限定符的模板语法的含义,c++,templates,syntax,semantics,C++,Templates,Syntax,Semantics,我最近看到: template <class U> struct ST { ... }; template <class U, class V> struct ST<U V::*> { ... }; 模板结构ST { ... }; 模板 结构街 { ... }; 我假设第二个模板是第一个模板的特化 但是U V::*的语义是什么?这意味着“指向类V的成员的指针,其中成员的类型是U”。比如说, struct X { int x = 0; }; //
template <class U> struct ST
{
...
};
template <class U, class V>
struct ST<U V::*>
{
...
};
模板结构ST
{
...
};
模板
结构街
{
...
};
我假设第二个模板是第一个模板的特化
但是U V::*
的语义是什么?这意味着“指向类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
struct X
{
int x=0;
};
// ...
intx::*p=&X::X//