Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

overloading operator== and casting

39 views
Skip to first unread message

Popping mad

unread,
Feb 20, 2017, 10:50:30 AM2/20/17
to le...@nylxs.com
I have two object type that I wanted to compare to each other using the
operator== but to my surprise, which I compiled it, I got a complaint
about the different types being used without cast


euler.cpp|113 col 28| error: comparison between distinct pointer types
‘tree::Predicate<int, int>*’ and ‘tree::Node<int>*’ lacks a cast


my overload operator knows this already

class Predicate{
public:
Predicate(Node<node_type>& in_a, Node<node_type>& in_b,
Edge<bridge_type>& in_c)
: a{in_a}, b{in_b}, c{in_c}{
a.data++;
b.data++;
};
...

bool operator==(const Node<node_type>& first)

Can anyone suggest the cleanest means of working around this annoying
error.

Alf P. Steinbach

unread,
Feb 20, 2017, 11:01:12 AM2/20/17
to
You can't overload `==` for raw pointer types, and you're not doing
that. Your overload is for references/values.


Cheers!,

- Alf

Juha Nieminen

unread,
Feb 21, 2017, 7:09:01 AM2/21/17
to
Popping mad <rai...@colition.gov> wrote:
> euler.cpp|113 col 28| error: comparison between distinct pointer types
> ???tree::Predicate<int, int>*??? and ???tree::Node<int>*??? lacks a cast

You are comparing pointers, not values.

Are you sure you didn't intend to write "*ptr1 == *ptr2"
instead of "ptr1 == ptr2"?

ruben safir

unread,
Feb 23, 2017, 3:10:23 PM2/23/17
to
On 02/21/2017 07:08 AM, Juha Nieminen wrote:
> You are comparing pointers, not values.
>
> Are you sure you didn't intend to write "*ptr1 == *ptr2"
> instead of "ptr1 == ptr2"?


that is a good suggestion, but I fixed this a week ago and forgot how I
fixed it already

Öö Tiib

unread,
Feb 24, 2017, 5:13:27 PM2/24/17
to
And also you already deleted the file and so you can't look into it to
figure out how you fixed it.
0 new messages