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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:25:34+00:00 2026-06-09T19:25:34+00:00

In C++ compiled with -O3, does inheritance without virtuality have a cost in terms

  • 0

In C++ compiled with -O3, does inheritance without virtuality have a cost in terms of :

  • execution time
  • memory

If the answer is yes : why ?

As an example : are MyClass1 and MyClass2 equivalent in terms of performance and memory ?

enter image description here

  • 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-09T19:25:35+00:00Added an answer on June 9, 2026 at 7:25 pm

    execution time

    Of what? Functions are resolved statically, so function calls are the same. MyClass1‘s constructor will call the constructors of base classes, and its destructor will call destructors of base classes, so for construction & destruction there may be some overhead. Maybe. Some compilers might optimize the calls away.

    memory

    This will be the same, both only have a member double. Theoretically. Depends on the implementation I guess, as it’s not mandated by the standard, but most commonly there will be no memory overhead.

    Note that deleting an object MyClass1 through a pointer to Derived results in undefined behaviour, because there’s no virtual destructor.

    Note 2 inheritance without polymorphism is a code smell. Not saying it’s wrong, but in most cases composition is better.

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

Sidebar

Related Questions

Does using virtual inheritance in C++ have a runtime penalty in compiled code, when
Does the structure of a C# file affect what is compiled? For example, would
When managing shader's, does it make sense to have all of them compiled and
How does virtual functions work behind the scenes in Inheritance ? Does the compiler
Does WPF compiled code is bigger or smaller than Winform compiled code? Does WPF
My compiled Go code does not end with an extension on Linux. Any tips
How does HTML work? Does it get parsed, compiled and then executed? Does it
How does a SQL query work? How does it get compiled? Is the from
Template code is not compiled until the template function is used. But where does
I've just downloaded from SVN the DUnit2 code base. Does someone has compiled it

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.