在一段代码中,我发现如下内容:
template<typename T>
class IsClassT {
private:
typedef char One;
template<typename C> static One test(int C::*);
...
问题是我在哪里可以找到关于为什么“int C::*”的用法在函数 test() 定义中有效的描述?
最佳答案
int C::*
是指向 int
类型的 C
成员的指针。搜索“指向成员的指针”。处理此声明语法的标准部分 (ISO/IEC 14882:2003) 是 8.3.3 指向成员的指针 [dcl.mptr]。
示例用法。
struct Example
{
int a;
int b;
};
int test( Example& ex, int Example::* p )
{
return ex.*p;
}
int main()
{
Example x = { 3, 5 };
// Convoluted way of extracting x.a and x.b
int a = test( x, &Example::a );
int b = test( x, &Example::b );
}
关于c++ - 在哪里可以找到有关 "int C::*"用法的说明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6890331/