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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:51:03+00:00 2026-06-01T03:51:03+00:00

why overriding is resolved at runtime whereas overloading is resolved at compile time ?

  • 0

why overriding is resolved at runtime whereas overloading is resolved at compile time ?
is there any reason that overriding cant be resolved at compile time.

  • 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-06-01T03:51:04+00:00Added an answer on June 1, 2026 at 3:51 am

    is there any reason that overriding cant be resolved at compile time.

    Assuming you’re talking about polymorphism, i.e.

    #include <iostream>
    
    class Base
    {
    public:
        virtual void Foo()
        {
            std::cout << "Base::Foo()" << std::endl;
        }
    };
    
    class Derived : public Base
    {
    public:
        virtual void Foo()
        {
            std::cout << "Derived::Foo()" << std::endl;
        }
    };
    

    The above code allows something like this to work as expected:

    void CallFoo(Base& b)
    {
        b.Foo(); 
    }
    
    int main()
    {
        Base b;
        Derived d;
        CallFoo(b); // calls Base::Foo()
        CallFoo(d); // Calls Derived::Foo();
    }
    

    It is important to realize that CallFoo() knows nothing about what b actually is (it could be referring to a Base instance or to a Derived instance). All CallFoo() gets is a reference to Base, which tells nothing about what it actually refers to, so there’s no way a compiler can tell what it is when it compiles CallFoo(). Therefore, determining whether Base::Foo() or Derived::Foo() should be called is necessarily a runtime decision.

    Removing the virtual keywords (to disable overriding) would cause the above code to print out Base::Foo() twice, not Base::Foo() then Derived::Foo(). This is because without the virtual keyword the compiler would simply resolve the call to Base::Foo() at compile time.

    That being said, because virtual functions incur some overhead (after all, the right function that needs to be called is a runtime decision), compilers will try their best to figure out the actual type of b in CallFoo() if it can. In that case, it becomes a compile-time decision. It is, however, an implementation detail.

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

Sidebar

Related Questions

Given, Method overloading = compile time resolution. Method overriding = run-time resolution. How does
When overriding the MembershipProvider and calling it directly, is there a way to fill
When overriding the equals() function of java.lang.Object, the javadocs suggest that, it is generally
I saw that there's many, many thread about this on the web, also in
I'm having trouble overriding the Code Signing Identity and provisioning profile that are specified
Are there any reasons why Equals or GetHashCode should be overriden in entities when
I do know the syntactical difference between overriding and overloading. And I also know
When overriding a virtual method, I noticed that when I make a mistake in
I know that when overriding hashcode() and equals() of my persistent entities I should
I've read the Overriding and Hiding Methods tutorial. And from that, I gathered the

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.