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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:02:16+00:00 2026-05-12T11:02:16+00:00

class Temp { private: ~Temp() {} friend class Final; }; class Final : virtual

  • 0
class Temp
{
private:
    ~Temp() {}
    friend class Final;
};

class Final : virtual public Temp
{
public:
     void fun()
     {
         cout<<"In base";
     }
};

class Derived : public Final
{
};

void main()
{
    Derived obj;
    obj.fun();
}

The above code tries to achieve non-inheritable class (final). But using above code the object of derived can still be created, why?

The desired functionality is achieved only if ctor made private, my question is why it is not achievable in case of dtor 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-05-12T11:02:16+00:00Added an answer on May 12, 2026 at 11:02 am

    Well, for this program (pleasse provide correct, compilable examples)

    #include <iostream>
    
    class Temp
    {
    private:
        ~Temp() {}
        friend class Final;
    };
    
    class Final : virtual public Temp
    {
    public:
        void fun() { std::cout<<"In base"; }
    };
    
    class Derived : public Final {};
    
    int main() {
        Derived obj;
        obj.fun();
    }
    

    Comeau Online says

    Comeau C/C++ 4.3.10.1 (Oct  6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
    Copyright 1988-2008 Comeau Computing.  All rights reserved.
    MODE:strict errors C++ C++0x_extensions
    
    "ComeauTest.c", line 16: error: "Temp::~Temp()" (declared at line 6) is inaccessible
      class Derived : public Final {
                             ^
              detected during implicit generation of "Derived::Derived()" at line
                        21
    
    "ComeauTest.c", line 16: error: "Temp::~Temp()" (declared at line 6) is inaccessible
      class Derived : public Final {
            ^
              detected during implicit generation of "Derived::~Derived()" at line
                        21
    
    2 errors detected in the compilation of "ComeauTest.c".
    

    Since, when in doubt, I always trust como (I have only ever found one error in it, but many in other compilers), I suppose VC9 (which accepts the code) is in error. (From that void main() I suppose you use VC, too.)

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

Sidebar

Ask A Question

Stats

  • Questions 174k
  • Answers 174k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can create a closure and assign i to a… May 12, 2026 at 2:52 pm
  • Editorial Team
    Editorial Team added an answer The HTMLEditorKit is not an HTML editor but an editor… May 12, 2026 at 2:52 pm
  • Editorial Team
    Editorial Team added an answer You can use a reference counted pointer like boost::shared_ptr<> to… May 12, 2026 at 2:52 pm

Related Questions

For example, say I have a class Temp: class Temp { public: int function1(int
const int MIN_NUMBER = 4; class Temp { public: Temp(int x) : X(x) {
I was reading about volatile member function and came across an affirmation that member
When I compiled my C++ code with GCC 4.3 for the first time, (after

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.