Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 95735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:42:17+00:00 2026-05-10T23:42:17+00:00

I have a function with the same name, but with different signature in a

  • 0

I have a function with the same name, but with different signature in a base and derived classes. When I am trying to use the base class’s function in another class that inherits from the derived, I receive an error. See the following code:

class A {     public:     void foo(string s){}; };  class B : public A {     public:     int foo(int i){}; };  class C : public B {     public:     void bar()     {         string s;         foo(s);     } }; 

I receive the following error from the gcc compiler:

In member function `void C::bar()': no matching function for call to `C::foo(std::string&)' candidates are: int B::foo(int) 

If I remove int foo(int i){}; from class B, or if I rename it from foo1, everything works fine.

What’s the problem with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:42:18+00:00Added an answer on May 10, 2026 at 11:42 pm

    Functions in derived classes which don’t override functions in base classes but which have the same name will hide other functions of the same name in the base class.

    It is generally considered bad practice to have have functions in derived classes which have the same name as functions in the bass class which aren’t intended to override the base class functions as what you are seeing is not usually desirable behaviour. It is usually preferable to give different functions different names.

    If you need to call the base function you will need to scope the call by using A::foo(s). Note that this would also disable any virtual function mechanism for A::foo(string) at the same time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Nearly a duplicate of: How to sort List<List<string>> according to… May 11, 2026 at 11:59 am
  • added an answer The image was corrupted in a way that IE7 could… May 11, 2026 at 11:59 am
  • added an answer No, I don't think you can easily do that with… May 11, 2026 at 11:59 am

Related Questions

I have a function with the same name, but with different signature in a
I have a function in an external library that I cannot change with the
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,
Currently I have the function CreateLog() for creating a a log4net Log with name
I have a class with the following member functions: /// caller pid virtual pid_t
So i have a piece of assembly that needs to call a function with
I have a Delphi DLL with a function defined as: function SubmitJobStringList(joblist: tStringList; var
I have a bash script file which starts with a function definition, like this:
I have a simple function in which an array is declared with size depending
I'm mocking about with plt-scheme's ffi and I have a C-function that returns a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.