2017-01-11 3 views
2

Ich fand diesen Code in der MySQL-Quelle in der Datei set_var.h und ich bin mir nicht sicher, was Ulong SV :: * Offset bedeutet. KurzWas bedeutet Scope Auflösung der Struktur in einer Variablendeklaration?

Darin sieht so aus:

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) {...} 
} 

und so weiter.

+1

Es ist ein Zeiger-zu-Mitglied. –

Antwort

1

ulong SV::*offset; ist ein Mitglied der Klasse A namens offset, die zu einem Mitglied der Klasse weist SV vom Typ ulong. Es wird wie folgt verwendet:

#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; 
} 
Verwandte Themen