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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:24:40+00:00 2026-05-24T11:24:40+00:00

I have seen this question http://www.careercup.com/question?id=384062 class Base { public : virtual void method

  • 0

I have seen this question http://www.careercup.com/question?id=384062

class Base {
public :
    virtual void method () = 0;
private :
    int n;
};

void Base::method() { n = 1;}

class D1 : Base {};

class D2 : public D1 {
    int i;
    void method() {i = 2;}
};

It passed the compiler of vs2008 and g++ 4.4.3

Here is my understanding of above code, please correct me if I am wrong

S1> D1 has inherited variable Base::n but it cannot access it.

S2> D1 has inherited the function Base::method but it doesn’t call/modify this inherited function in the above implementation.

S3> D2::method is not an overridden version of D1::method

  • 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-24T11:24:41+00:00Added an answer on May 24, 2026 at 11:24 am

    D1 has inherited variable Base::n but it cannot access it.
    Correct.
    Private members of a class are never accessible from anywhere except the members of the same class.


    D1 has inherited the function Base::method but it doesn’t call/modify this inherited function in the above implementation.
    Correct, but conditonally, Read below for why:

    D1 inherits the Base::method but it is not calling/invoking it because you did’nt add any statement to do so. But it can call it.
    Pure virtual functions can have a body and they can be called by drived class members just like any other member function.

    class D1 : Base 
    {
        public:
            void doSomething()
            {
                Base::method();
            }
    
    }; 
    

    Note that in your Base class n is private so the only way to access it is through member function of Base & since only method() can do so, You can do it through it.

    Note that presence of atleast one pure virtual function makes an class Abstract Class, And one cannot create objects of an Abstract class. Any class deriving from an Abstract class must override ALL the pure virtual functions of the Base class or else the derived class becomes an Abstract class as well.

    Based on above rule,
    In your case both Base and D1 are Abstract classes.


    D2::method is not an overridden version of D1::method
    Incorrect
    Though method() is not acessible to the ouside world through instance of class D1, it is still very much a part of it. Access control dictates access rights not presence or absence of members.
    So, Yes, D2::method is an overriden version of D1::method and it hides it as well, just that in this case, D1::method was not acccessible in the first place

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

Sidebar

Related Questions

I have seen this question: Are there any decent UI components for touch screen
Now I have seen this question in another forum but it didn't had an
Haven't seen many Geneva related questions yet, I have posted this question in the
Please have a look at this beautiful website : http://www.snipe.net/ If you are using
This question seems to have been asked a lot, but I haven't seen an
I really was trying to avoid asking this question. I have seen quite a
I have seen this question: How to keep WPF TextBox selection when not focused?
I have seen this question asked here a few times, but most question didn't
I have seen this problem arise in many different circumstances and would like to
I have seen this link: Implementing Mutual Exclusion in JavaScript . On the other

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.