Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带范围限定符的模板语法的含义_C++_Templates_Syntax_Semantics - Fatal编程技术网

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//