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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:05:24+00:00 2026-05-13T12:05:24+00:00

How it is determined whether the below call is bound at compile time or

  • 0

How it is determined whether the below call is bound at compile time or at runtime?

object.member_fn;//object is either base class or derived class object
p->member_fn;//p is either base class or derived class pointer

EDITED:

#include <iostream>
using namespace std;
class Base
{
       public:
          Base(){ cout<<"Constructor: Base"<<endl;}
          ~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
     //Doing a lot of jobs by extending the functionality
       public:
           Derived(){ cout<<"Constructor: Derived"<<endl;}
           ~Derived(){ cout<<"Destructor : Derived"<<endl;}
 };
void foo()
{
    Base & Var = Derived();
    Base*pVar = new Derived;
    delete pVar;
}
void main()
{
    foo();
        std::cin.get();
}


out put:
Constructor: Base
Constructor: Derived
Constructor: Base
Constructor: Derived
Destructor : Base // the Derived is not called,
                  // the PVal is of type Base* and the fn is not virtual 
                  //so compile time binding
Destructor : Derived
Destructor : Base
  • 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-13T12:05:24+00:00Added an answer on May 13, 2026 at 12:05 pm

    If the method is not virtual, both calls will be resolved at compile time. If the method is virtual then the first call in your question (obj.method()) will be resolved at compile time for an object, but at runtime for a reference. The second call (objp->method()) will be resolved at runtime. You can also force at compile time to call the non-derived version of a method.

    struct base {
       void f();
       virtual void v();
    };
    struct derived : public base {
       void f();
       void v(); // intentionally left virtual out, it does not really matter
    };
    int main() {
       derived d;
       base & b = d;
       base * bp = &d;
    
       // compile time:
       d.f();   // derived::f
       d.v();   // derived::v
       b.f();   // base::f   -- non-virtual
       bp->f(); // base::f   -- non-virtual
    
       // runtime:
       b.v();   // derived::v
       bp->v(); // derived::v
    
       // compile time (user forced):
       b.base::v();   // base::v
       bp->base::v(); // base::v
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 268k
  • Answers 268k
  • 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
  • Editorial Team
    Editorial Team added an answer After some playing about with varied locations for square braces… May 13, 2026 at 12:59 pm
  • Editorial Team
    Editorial Team added an answer Replace this in your code with MyActivity.this where MyActivity is… May 13, 2026 at 12:59 pm
  • Editorial Team
    Editorial Team added an answer The cache will automatically start removing items when your system… May 13, 2026 at 12:59 pm

Related Questions

I have a Drupal site with user logins. Embedded within this site is a
I am trying to get my head around the use of the Action delegate
How can I determine using jQuery that a given element is above the top
How can you remove one line which contains the word SID in many files?
Ever since I installed emacs on a new machine I have seen an ugly

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.