1

I want to know the below code is correct or not

class A
{
public :
    int show (int x, int y);
};

class B : public A
{
public : 
    float show (int a, int b); // can i overload this function ?
};

the show function is present in both base and derived class with different written types. I know function overloading concept (can not overload with different return types).

Is this possible to do so?

2
  • class & public: should all be lower case Commented Apr 26, 2011 at 6:44
  • Overloading won't work, what are you trying to achieve? Commented Apr 26, 2011 at 6:50

3 Answers 3

1

The code will be compiled successfully. The method A::show will not be overloaded but hidden.

You can call this method with the scope operator.

Sign up to request clarification or add additional context in comments.

Comments

0

Check this link or this link

Class A
{
Public :
virtual int show (int x, inty) = 0;
};

class B:Public A
{
Public : 
float show (int x, int y);
};

Comments

0

If you create a derived class object like

1)

B b; 
b.show(); 

OR

2)

A* b = new B();
b->show();

Will always look into derived class, and call B::show().

This is for your particular example, where no virtual functions are present, if virtual functions are present in the base class, the second case can give different results in other cases, but in this particular example even base class virtual functions will make no difference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.