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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:30:04+00:00 2026-06-07T08:30:04+00:00

Suppose I have a Base & Derived class: class Base{ private: int* _privateIntPtrB; protected:

  • 0

Suppose I have a Base & Derived class:

class Base{
 private:
  int* _privateIntPtrB;
 protected:
  int* _protectedIntPtrB;
 public:
  //methods which use
  //_privateIntPtrB and _protectedIntPtrB

class Derived: public Base{
 private:
  int* _privateIntPtrD;
 protected:
  int* _protectedIntPtrB; //I am redeclaring this var
 public:
  //methods which use
  //_privateIntPtrD and _protectedIntPtrB

My question:
In the methods of the Derived class, does the Derived version of _protectedIntPtrB get used? (I think it does, but want to confirm).

If a method is not redefined by the Derived class, which version of the _protectedIntPtrB will be used by a pointer to Derived class?

The reason I am asking – I want to initialize _protectedIntPtrB in the Derived class differently and want that version of the _protectedIntPtrB to be used in all the instances of Derived class.

  • 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-07T08:30:06+00:00Added an answer on June 7, 2026 at 8:30 am

    In the methods of the Derived class, does the Derived version of _protectedIntPtrB get used?

    Yes, it hides the base class member and so an unqualified use of _protectedIntPtrB in the scope of Derived refers to Derived::_protectedIntPtrB. (The base class variable is still available, if qualified as Base::_protectedIntPtrB).

    If a method is not redefined by the Derived class, which version of the _protectedIntPtrB will be used by a pointer to Derived class?

    The base-class variable. Data members of derived classes are not available from the base class.

    The reason I am asking – I want to initialize _protectedIntPtrB in the Derived class differently and want that version of the _protectedIntPtrB to be used in all the instances of Derived class.

    Usually, the best way to make derived classes behave differently to their base classes is by overriding virtual functions. It would probably be better if you had a think about exactly what you want to achieve: work out what behaviour you want to modify, and encapsulate that in a virtual function.

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

Sidebar

Related Questions

Suppose we have two classes: class Base { private: int x; public: void f();
Suppose I have a Base class and its derived class Derived as follows: class
Suppose I have the following (trivially simple) base class: public class Simple { public
Suppose I have an interface called Interface, and a concrete class called Base, which,
Suppose I have an abstract base class, that just defines a container on which
Suppose we have: class Base { __forceinline virtual int A() {return 1;} } class
Suppose I have a base class B, and a derived class D. I wish
Suppose I have 1 base class and a derived class. The derived class has
For example, suppose I have the following base class for which I cannot modify
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)

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.