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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:05:55+00:00 2026-05-25T23:05:55+00:00

As I understand it, the compiler can inline a virtual function call when it

  • 0

As I understand it, the compiler can inline a virtual function call when it knows at compile time what the type of the object will be at runtime (C++ faq).

What happens, however, when one is implementing a pure virtual method from a base class? Do the same rules apply? Will the following function call be inlined?

class base
{
public:
    virtual void print() = 0;

    virtual void callPrint()
    {
        print(); // will this be inline?
    }
};

class child : public base
{
public:
    void print() { cout << "hello\n"; }
};

int main()
{
    child c;
    c.callPrint();

    return 0;
}

EDIT:

I think my original example code was actually a poor representation of what I wanted to ask. I’ve updated the code, but the question remains the same.

  • 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-25T23:05:56+00:00Added an answer on May 25, 2026 at 11:05 pm

    The answer is of course “it depends”, but in principle there’s no obstruction to optimization. In fact, you’re not even doing anything polymorphic here, so this is really straight-forward.

    The question would be more interesting if you had code like this:

    child c;
    base & b = c;
    b.print();
    

    The point is that the compiler knows at this point what the ultimate target of the dynamic dispatch will be (namly child::print()), so this is eligible for optimization. (There are two separate opportunities for optimization, of course: one by avoiding the dynamic dispatch, and one coming from having the function body of the target visible in the TU.)

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

Sidebar

Related Questions

I can't understand why If I compile the same source with Visual Studio 2008
I understand that sizeof is an operator, which is evaluated at compile time to
In C++ I can declare a method inline and the compiler is likely to
As we all know javac inlines constants at compile time which can lead to
I do not understand why the compiler can not see that a cast is
can't understand this: g++ compiler is angry on: lengths.insert(pair<Deux,long>(d,one)); where struct Deux {long big;
I understand you can use the inline keyword or just put a method in
I can't understand how to get the google closure compiler for javascript to properly
I've been trying to understand what that really means : inline function In C++,
Any existing Flash SWF compilers that can understand directives like #IF #ENDIF , etc?

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.