I'm currently working on implementing a small game in C++, but when trying to compile, I get this error:

..quadtree.h:125: error: no matching function for call to 'Fleet::Ship::overlaps(const Fleet::Ship*&)'
..ship.h:40: note: candidates are: bool Ship::overlaps(const Rectangle&) const
..ship.h:85: note:                 bool Ship::overlaps(const Ship&) const
..ship.h:32: note:                 bool Ship::overlaps(const Point&) const

So I think I now have Ship*&, which should actually be Ship&.
Is there any way to convert Ship*& to Ship&?

Thanks

Recommended Answers

All 6 Replies

Post your code.

So I think I now have Ship*&, which should actually be Ship&.
Is there any way to convert Ship*& to Ship&?

Yes, of course: use unary operator *(). But I'm not sure that it helps ;)

//...
Ship old_ship;
Ship *new_ship=new Ship;
old_ship.overlaps(new_ship);
//...

i'm not sure too..

Use the following to make the function call

old_ship.overlaps(*new_ship);

You have defined to function to catch a reference and you are sending pointer the object which would be a mismatch

Member Avatar for jencas

In the function call here

'Fleet::Ship::overlaps(const Fleet::Ship*&)'

you are passing a pointer instead of a reference. Dereference the parameter by prefixing it with a '*'.

class A;

void func(A & a) {...}

A a;
A *p = &a;
func(*p); // like this

It's all solved now :)

Thanks

btw dereferencing the parameters worked

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.