在下面的示例代码中,我想知道在getSocialSecurityNumber类中传递给Citizen的参数是什么。为什么是(Passkey<Government>)而不是(Passkey<Government> x)。
它与类模板/函子有关吗?
#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;
}发布于 2018-11-06 21:20:08
Passkey<Government>是一种类型。参数显然没有使用,它没有名称。
https://stackoverflow.com/questions/53180116
复制相似问题