Question
8: Why doesn't this code compile? b) How to change the definition of Token class members so that the code compiled, and at the same
8: Why doesn't this code compile? b) How to change the definition of Token class members so that the code compiled, and at the same time that the objects in std :: set s are stored according to the comparator used? (C++)
1 #include 2 #include 34 class Token { 5 public: 6 int a(); 7 Token(int i0) : a(i0) {}; 8 bool operator<(const Token& t0) { return a < t0.a; } 9 }; 10 11 int main() { 12 bool (*comp)(const Token&, const Token&) = [](const Token& t0, const Token& t1) > bool { 13 return t0 < t1; 14 }; 15 16 std::set s(comp); 17 18 for(int i=0; i<3; ++i) { s.emplace(i); } 19 20 for(auto i : s) { std::cout << i.a << std::endl; } 21 22 return 0; 23 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started