0

Let's have following classes parent and child.

class parent
{

public:
    void Test(char* pParameter) {};
};

class child : parent
{
public:
    void Test(int pParameter) {};
};

How to solve following issue?

child* c = new child();
c->Test("cccc");

It returns: "const char *" is incompatible with parameter of type "int".

I found out these ways:

  1. Rename method
  2. Cast c to parent class ((parent*)c->Test("cccc");)
  3. Create in child class method Test(char*) calling the method in parent class.

I do not like neither one of the solutions. Is there any other?

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • 2
    Add `using parent::Test;` into `child` class. – songyuanyao Aug 31 '21 at 08:32
  • [This question](https://stackoverflow.com/questions/1628768/why-does-an-overridden-function-in-the-derived-class-hide-other-overloads-of-the) doesn't really answer your question, but hopefully explains the reason for the problem. – Lukas-T Aug 31 '21 at 08:38
  • And why should it be available because on top of name hiding, you are also using private inheritance. – Tanveer Badar Aug 31 '21 at 08:40

0 Answers0