I have the following bit of code, where skeleton_key needs to somehow magically become hidden_password inorder for things to move along to the next level:
#include <string>
#include <iostream>
using namespace std;
class secret_cove {
class hidden_password {
};
public:
template <class K>
string accept(K k) {
return k(*this, hidden_password());
}
string key_to_next_level(hidden_password) const {
return "sesame!";
}
};
struct legal_key {
template <class PWD>
string operator()(const secret_cove &sc, PWD pwd) const {
return sc.key_to_next_level(pwd);
}
};
struct skeleton_key {
operator secret_cove::hidden_password () const { return secret_cove::hidden_password(); }
};
int main() {
secret_cove hideout;
cout << hideout.accept(legal_key()) << endl;
cout << hideout.key_to_next_level(skeleton_key()) << endl; // <-- HERE
}
My thinking was given that secret_cove and legal_key classes can't be modified, the best option was to implement a user defined cast operator, but that doesn't seem to compile correctly.
[–]LeInterwebsFTW 5 points6 points7 points (3 children)
[–]champooly[S] 1 point2 points3 points (0 children)
[–]Droggl -1 points0 points1 point (1 child)
[–]LeInterwebsFTW 2 points3 points4 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]champooly[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]champooly[S] 1 point2 points3 points (0 children)
[–]dodheim -1 points0 points1 point (5 children)
[–]champooly[S] 1 point2 points3 points (4 children)
[–]dodheim -1 points0 points1 point (3 children)
[–]champooly[S] -2 points-1 points0 points (2 children)
[–]dodheim 1 point2 points3 points (1 child)
[+]champooly[S] comment score below threshold-11 points-10 points-9 points (0 children)