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 7622349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:25:43+00:00 2026-05-31T04:25:43+00:00

Please definitively explain what the method resolution rules are in the following case. I

  • 0

Please definitively explain what the method resolution rules are in the following case. I have an idea, based on the behavior of the code, but would like clarification.

Based on “The const-ness of the calling object determines which version of MyArray::Get() will be invoked and thus whether or not the caller is given a reference with which he can manipulate or only observe the private data in the object. The two methods technically have different signatures because their “this” pointers have different types, allowing the compiler to choose the right one” from wikipedia const correctness, I would conclude that my example should be a case of method overloading, not method overriding (since a const method and a non-const method have two different signatures).

class Base
{
public:

    void test()
    { std::cout << "nonconst call" << std::endl; }
};

class Child : public Base
{
public:

    void test() const
    {
        std::cout << "const call" << std::endl;
        Child * nonConstThis = const_cast<Child * >(this);
        Base * nonConstBase = dynamic_cast<Base * >(nonConstThis);

        // This call leads to infinite recursion by calling
        // "void Child::test() const", which implies that
        // a "Child *" will resolve to calling a const Child function
        // before calling a non-const Base function.
        //nonConstThis->test();

        // This will call "void Base::test()"
        nonConstBase->test();
    }

};

void main()
{
    Child * child = new Child;
    child->test();
}
  • 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-31T04:25:45+00:00Added an answer on May 31, 2026 at 4:25 am

    It’s actually method hiding, not overloading.

    When you create a method with the same name in a derived class, the base class version is no longer visible.

    struct A
    {
        void foo() {}
    };
    
    struct B : public A
    {
        void foo(int x) {}
    };
    
    B b;
    b.foo(); //error
    

    I’m assuming you expect B::foo() to exist, but, as you can see, it does not. So nothing, not cv-qualifiers (const) or parameters affect this.

    In your case the name isn’t resolved because it has something to do with the const, but because you’re calling test on an object of type Child. You then call Base::test() on an object of type Base, just like the following would work form my example:

    ((A)b).foo();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please explain the difference in how the 2 snippets of code are
Please explain to me why the very last echo statement is blank? I expect
Please, provide code examples in a language of your choice. Update : No constraints
Can someone please help me understand the following: In the previous version of NHibernate
I came across the following code snippet and needed to predict the output. My
please take a look at the two following c statements printf(a very long string);
I have this piece of code: begin complete_results = Timeout.timeout(4) do results = platform.search(artist,
First, please bear with me. I have hard time telling others my problem and
I don't know how to explain this very well, but here's a shot at
I have some generated classes, which are generated with ASCII encoding. But to compile

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.