Reputation: 57
I'm doing an OOP project for school, and I'm currently stuck because of the following problem :
Let's say that A
is my base class, that B
inherits from A
and C
inherits from B
.
A
has a method to check whether two A-type objects are colliding.
This method is not redefined/overdriven in C
, but I have to use it in this subclass.
class A
{
public:
bool isColliding(A);
};
class B : public A
{
};
class C : public B
{
public:
void Eat(B);
}
void C::Eat(B objectB)
{
if(isColliding(objectB))
{
}
}
This is an oversimplification of the code, I was just trying to convey the idea.
It returns the following :
error : no matching function for call to 'C::isColliding(B)'
note: candidate: bool A::isColliding(A)
note: no known conversion for argument 1 from 'B' to 'A'.
How do I get this method to interpret C and B as being A for it to work ?
Upvotes: 1
Views: 188
Reputation: 27577
In order to access a base-class member, you have to say so explicitly, like this:
if(A::isColliding(objectB)) {
Upvotes: 2