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

  • SEARCH
  • Home
  • 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 830135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:59:40+00:00 2026-05-15T03:59:40+00:00

I have the following code which is seems to be lead to the infinite

  • 0

I have the following code which is seems to be lead to the infinite loop:

struct X
{
  void my_func( int ) { std::cout << "Converted to int" << std::endl; }
};

struct X2 : X
{
  void my_func( char value ) { my_func(value); }
};

What is the problem with it?

  • 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. Editorial Team
    Editorial Team
    2026-05-15T03:59:41+00:00Added an answer on May 15, 2026 at 3:59 am

    The second bit is infinitely recursive:

    struct X2 : X
    {
      void my_func( char value ) { my_func(value); } //calls itself over and over again
    };
    

    Prefix my_func with the name of the base class and you will be OK

    struct X2 : X
    {
      void my_func( char value ) { X::my_func(value); }
    };
    

    EDIT Just realised that base class my_func‘s signature is different. C++ compiler resolves the function overload statically, that means it will pick the function that best matches the type of the argument, that’s why it calls the char overload.

    For example:

    char cChar = 'a';
    
    myfunc(cChar);
    
    void myfunc(char a){} //<-- this one is called
    void myfunc(int a){}
    
    int iInt = 1;
    
    myfunc(iInt);
    
    void myfunc(char a){} 
    void myfunc(int a){} //<-- this one is called
    

    Thanks Charles Bailey. The above code does not apply in this case as X2‘s my_func hides base class’s my_func. This leaves the only solution to qualify the function with the class name.

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

Sidebar

Related Questions

I have the following code which seems to work: class MapCell { public: int
I have following code which seems to work fine: <%if group.employees.count > 0%> <td><%=
I have the following code which seems to blow up if the column in
I have the following code which seems to throw a Invalid cross-thread access. and
Ok so i have the following code setup which seems to work fine: user
I have the following code, which seems to override the jQuery.error function: $.test =
I have the following code which seems to work OK except for a minor
Hello I have the following bit of code which seems to work, but I'm
i have the following code which seems very slow and I wanted to see
I have the following sample code which doesn't seem to want to run. import

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.