0

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;
}
Blood-HaZaRd
  • 2,049
  • 2
  • 20
  • 43

1 Answers1

3

Passkey<Government> is a type. The parameters is obviously not used, it has no name.

Swordfish
  • 12,971
  • 3
  • 21
  • 43