变量声明中结构的范围解析是什么意思?
What means scope resolution of structure in a variable declaration?
我在文件 set_var.h 的 MySQL 源代码中找到了这段代码,我不确定 ulong SV::*offset 是什么意思。
简而言之,它看起来像:
struct SV {...}
class A {
ulong SV::*offset;
A(ulong SV::*offset_arg): offset(offset_arg) {...}
};
class B {
DATE_TIME_FORMAT *SV::*offset;
B(DATE_TIME_FORMAT *SV::*offset_arg) : offset(offset_arg) {...}
}
等等。
ulong SV::*offset;
是名为 offset
的 class A
的成员,它指向 class SV
类型的成员ulong
。它是这样使用的:
#include <iostream>
using ulong = unsigned long;
struct SV {
ulong x, y, z;
};
int main()
{
// A pointer to a ulong member of SV
ulong SV::*foo;
// Assign that pointer to y
foo = &SV::y;
// Make an instance of SV to test
SV bar;
bar.x = 10;
bar.y = 20;
bar.z = 30;
// Dereference with an instance of SV
// Returns "20" in this case
std::cout << bar.*foo;
return 0;
}
我在文件 set_var.h 的 MySQL 源代码中找到了这段代码,我不确定 ulong SV::*offset 是什么意思。
简而言之,它看起来像:
struct SV {...}
class A {
ulong SV::*offset;
A(ulong SV::*offset_arg): offset(offset_arg) {...}
};
class B {
DATE_TIME_FORMAT *SV::*offset;
B(DATE_TIME_FORMAT *SV::*offset_arg) : offset(offset_arg) {...}
}
等等。
ulong SV::*offset;
是名为 offset
的 class A
的成员,它指向 class SV
类型的成员ulong
。它是这样使用的:
#include <iostream>
using ulong = unsigned long;
struct SV {
ulong x, y, z;
};
int main()
{
// A pointer to a ulong member of SV
ulong SV::*foo;
// Assign that pointer to y
foo = &SV::y;
// Make an instance of SV to test
SV bar;
bar.x = 10;
bar.y = 20;
bar.z = 30;
// Dereference with an instance of SV
// Returns "20" in this case
std::cout << bar.*foo;
return 0;
}