In a sample code (below) I am wondering what is the parameter passed to the getSocialSecurityNumber
in the Citizen
class. Why is it (Passkey<Government>)
and not (Passkey<Government> x)
.
Is it related to class template / functor ?
#include <string>
#include <iostream>
using namespace std;
template <typename T>
class Passkey {
private:
friend T;
Passkey() {}
Passkey(const Passkey&) {}
Passkey& operator=(const Passkey&) = delete;
};
class Citizen {
public:
string getSocialSecurityNumber(Passkey<Government>) const { return _socialSecurityNumber; };
^^^^ (here)
private:
string _socialSecurityNumber;
};
class Government {
private:
void printCitizenInfo(const Citizen &citizen) const;
};
void Government::printCitizenInfo(const Citizen &citizen) const {
cout << "Citizen SSN: " << citizen.getSocialSecurityNumber(Passkey<Government>()) << endl;
}