Comparing vector elements or address?

I want to compare the actual object stored in the vector. I was wondering if this is comparing the address or the value of the object in the vector. The > operator has been overloaded for this object.
selectedHandB and selectedHandA are pointers
1
2
3
4
if((&selectedHandB)[0] > (&selectedHandA)[0])
    {
        std::cout << " B > A " << std::endl;
    }
looks a pointer comparison to me.

(&b) address of b, which is already a pointer you say, so this is now a ** to an object. [0] thanks to () pulls it back to the original.

That is, if I am reading it right, your code is identical to

if( selectedHandB > selectedHandA) because the & and [0] cancel out.

Others can double check me. This is what happens when you write things with a convoluted style ... it is confusing to read.


I don't know what your exact situation is, but:

If you are using vectors, why do you need pointers?

Prefer references over pointers, where you can.

If operator> is overloaded, why send it pointers?

You can look in the debugger to see what is happening.
My apologies if adding () made it too difficult for you to read. It's easier for me to visually see it this way.

And I want to use references but I have a structure of pointers (to vectors) of objects (class) to determine who goes first and in what order. They then decide which cards they want. Line 3 was irrelevant. It was just to check to see if the address or element was being compared. It was in fact the element but i was curious why it isn't a *.

Is there a more efficient way of doing this?
Topic archived. No new replies allowed.