|
|
Nicolas Alvarez <nic### [at] gmailisthebestcom> wrote:
> Ahh, then I can say I did figure out both.
Ok, if you want a harder puzzle, here's a curious quirk about C++ (not
related to memory leaks, though):
//------------------------------------------------------------------------
#include <map>
struct A { int i; };
struct Comp
{ bool operator()(const A& a1, const A& a2) const { return a1.i < a2.i; }
};
int main()
{
std::map<A, int, Comp> theMap(Comp());
A a = { 1 };
theMap[a] = 5;
}
//------------------------------------------------------------------------
a) This doesn't compile. Without using a compiler, can you tell where
is the problem and what is the exact reason why it doesn't compile?
b) If you can't see it, try it with a compiler. I bet you still can't see
the problem... :P
c) In the erroneous line, can you tell me exactly what that line means?
d) What is the easiest way (smallest amount of extra code) to make it
compile and work as expected?
--
- Warp
Post a reply to this message
|
|