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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:34:39+00:00 2026-06-10T08:34:39+00:00

C++11 introduces keyword final , which makes it illegal to derive from a type.

  • 0

C++11 introduces keyword final, which makes it illegal to derive from a type.

Is there a way to achieve a similar result with C++03, perhaps by making certain member functions private?

  • 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-10T08:34:41+00:00Added an answer on June 10, 2026 at 8:34 am

    There are two solutions for C++03:


    First solution: private virtual friend base class with private default constructor:

    Based on this answer, with the difference that template are not used – thus we can make virtual base class a friend to “final” class.

    class A;
    class MakeAFinal {
    private: 
      MakeAFinal() {}   
      // just to be sure none uses copy ctor to hack this solution!
      MakeAFinal(const MakeAFinal&) {}   
      friend class A;
    };
    
    class A : private virtual MakeAFinal {
    // ...
    };
    

    Frankly I did not like this solutions, because it adds the unnecessary virtual-ism.
    All this can be enclosed in macros, to increase readability and easiness of usage:

    #define PREPARE_CLASS_FINALIZATION(CN) \
      class CN; \
      class Make##CN##Final { \
        Make##CN##Final() {} \
        Make##CN##Final(const Make##CN##Final&) {} \
        friend class CN; }
    
    #define MAKE_CLASS_FINAL(CN) private virtual Make##CN##Final
    
    PREPARE_CLASS_FINALIZATION(A);
    class A : MAKE_CLASS_FINAL(A) {
    // ...
    };
    

    Second solution: all constructors are private (including copy constructor). Instances of the class are created with help of friend class:

    class AInstance;
    class A {
    // ...
    private:
    // make all A constructors private (including copy constructor) to achieve A is final
      A() {}
      A(const A&) {} // if you like to prevent copying - achieve this in AFinal
      // ...
      friend class AInstance;
    };
    struct AInstance {
      AInstance() : obj() {}
      AInstance(const AInstance& other) : obj(other.obj) {}
      // and all other constructors
      A obj;
    };
    
    // usage:
    AInstance globalA;
    int main() {
      AInstance localA;
      AInstance ptrA = new AInstance();
      std::vector<AInstance> vecA(7);
      localA = globalA;
      *ptrA = localA;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

C# 4.0 introduces dynamic keyword, which will look up at run-time. Does this mean
C++11 introduces a new way of finishing program execution— std::quick_exit . Quoting the N3242
So MVC 4 introduces script and style bundling. Which allows for this: public static
I am making a program which makes use of a couple of constants. At
The dynamic keyword in C# 4 introduces new ways to work with objects that
The new introduced code convention require to use the final keyword where possible. The
pls tell me in which version dynamic keyword is introduced ? I found strange
There is a tutorial video that introduces Spring MVC 3.0. In the demo-project they
I am having trouble distinguishing a keyword from a non-keyword when a grammar allows
So there is the old pear installer and pyrus which is the new package

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.