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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:16:29+00:00 2026-05-11T22:16:29+00:00

In C++, it is legal to give an implementation of a pure virtual function:

  • 0

In C++, it is legal to give an implementation of a pure virtual function:

class C
{
public:
  virtual int f() = 0;
};

int C::f() 
{
  return 0;
}

Why would you ever want to do this?

Related question: The C++ faq lite contains an example:

class Funct {
public:
  virtual int doit(int x) = 0;
  virtual ~Funct() = 0;
};

inline Funct::~Funct() { }  // defined even though it's pure virtual; it's faster this way; trust me

I don’t understand why the destructor is declared pure virtual and then implemented; and I don’t understand the comment why this should be faster.

  • 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-11T22:16:29+00:00Added an answer on May 11, 2026 at 10:16 pm

    Declared destructors must always be implemented as the implementation will call them as part of derived object destruction.

    Other pure virtual functions may be implemented if they provide a useful common functionality but always need to be specialized. In the case, typically derived class implementations will make an explicit call to the base implementation:

    void Derived::f()
    {
        Base::f();
    
        // Other Derived specific functionality
    }
    

    Typically, you make a destructor virtual if you need to make a class abstract (i.e. prevent non-derived instances from being created) but the class has no other functions that are naturally pure virtual. I think the ‘trust me it’s faster’ is refering to the fact that because destructors called as part of derived object clean up don’t need to use a vtable lookup mechanism, the inline implementation can be taken advantage of, unlike typical virtual function calls.

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

Sidebar

Related Questions

Is this valid/portable/legal code: class Vector3 { public: float& operator [] ( const size_t
Is the following legal C++ code: class C { static public int x; };
This isn't legal: public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {}
Is it legal? class SomeClass { public: static void f(); }; using SomeClass::f; Edit:
Is this legal and/or good practice? #define SOFTWARE_VERSION_NUMBER 7.0v1.1 Want struct to always contain
I want to do public class Settings { static final URL logo = new
Is this legal? If not, will the following code allow this? class Foo {
Is this legal C++? struct foo { int a[100]; int b[sizeof(a) / sizeof(a[0])]; };
Is the following code the case of legal forward referencing? if yes why? public
You may argue that this question has a legal flavor to it, and that

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.