I have two containers with the type of A

A<string, double> s1;
A<string, bool> s2;

So I wrote the A class with the necessary functions and I used a

template<class T, class E>

for it. It has a function that returns a value of E, in my case, it returns a double which I'm trying to compare to another double. I'm supposed to overload the < operator for that, but I have no idea how to do that.

4.5 < s1.at("a");

s1.at("a"); returns 1.5, so it's false. I need it to return true.
I thought since they are both double values, I can just

bool operator< (double& rhs) {
    return rhs < *this;
}

But it's not working. I also thought it should be friend with two parameters, but it just doesn't make sense since the rhs is a double returned by a function, not a type of A.
So I guess it really is two different types and that's why my first idea is not working.

You can not change the behaviour of < being used with two doubles. The only thing you could do is to make at return a custom type instead of E, like a Proxy<E>. Then you could define static bool operator<(E, Proxy<E>) and that one will be called when you do 4.5 < s1.at("a").

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.