If I have a base abstract class with a function that takes it's own class as a parameter:
class Component abstract
{
public:
virtual bool Method(Component& other) = 0;
};
And I have a child class which overrides and overloads this function to take a parameter of its class:
class DerivedComponent : public Component
{
public:
virtual bool Method(Component& other) override;
virtual bool Method(DerivedComponent& other);
};
And I use these as components of another class, as such:
class Foo
{
private:
Component* m_component;
public:
Foo()
{
m_component = new DerivedComponent();
}
Component* GetComponent()
{
return m_component;
}
};
And I call the component's method, passing in Foo
's component:
Foo foo1 = Foo();
Foo foo2 = Foo();
foo1.GetComponent()->Method(*foo2.GetComponent());
Why does it call the DerivedComponent
's first un-overloaded method, Method(Component& other)
, instead of Method(DerivedComponent& other)
?