943,911 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 694
  • C++ RSS
Dec 4th, 2008
0

Point*& to Point&

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

C++ Syntax (Toggle Plain Text)
  1. ..quadtree.h:125: error: no matching function for call to 'Fleet::Ship::overlaps(const Fleet::Ship*&)'
  2. ..ship.h:40: note: candidates are: bool Ship::overlaps(const Rectangle&) const
  3. ..ship.h:85: note: bool Ship::overlaps(const Ship&) const
  4. ..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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JD2000 is offline Offline
2 posts
since Dec 2008
Dec 4th, 2008
0

Re: Point*& to Point&

Post your code.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Dec 4th, 2008
0

Re: Point*& to Point&

Click to Expand / Collapse  Quote originally posted by JD2000 ...
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
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Dec 5th, 2008
0

Re: Point*& to Point&

C++ Syntax (Toggle Plain Text)
  1. //...
  2. Ship old_ship;
  3. Ship *new_ship=new Ship;
  4. old_ship.overlaps(new_ship);
  5. //...
i'm not sure too..
Last edited by cikara21; Dec 5th, 2008 at 4:01 am.
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Dec 5th, 2008
0

Re: Point*& to Point&

Use the following to make the function call

[code = C++]
old_ship.overlaps(*new_ship);
[/code]

You have defined to function to catch a reference and you are sending pointer the object which would be a mismatch
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sweeya is offline Offline
8 posts
since Nov 2008
Dec 5th, 2008
0

Re: Point*& to Point&

In the function call here
C++ Syntax (Toggle Plain Text)
  1. 'Fleet::Ship::overlaps(const Fleet::Ship*&)'
you are passing a pointer instead of a reference. Dereference the parameter by prefixing it with a '*'.

C++ Syntax (Toggle Plain Text)
  1. class A;
  2.  
  3. void func(A & a) {...}
  4.  
  5. A a;
  6. A *p = &a;
  7. func(*p); // like this
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Dec 9th, 2008
0

Re: Point*& to Point&

It's all solved now

Thanks

btw dereferencing the parameters worked
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JD2000 is offline Offline
2 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: All the programmers
Next Thread in C++ Forum Timeline: C++ Radix Sort - Bitshift Operators





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC