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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:41:15+00:00 2026-05-21T16:41:15+00:00

#include stdafx.h #include <iostream> using namespace std; class A { public: int a,b,c; A()

  • 0
#include "stdafx.h"
#include <iostream>
using namespace std;

class A
{
public:
  int a,b,c;
  A()
  {
      a=0;
      b=0;
      c=0;
  }
};

class B:public A
{
public:
    void get()
    {
        A *a2 =new A;
        a2->a=10;
        a2->b=20;
        a2->c=30;
        cout<<a2->a<<""<<a2->b<<""<<a2->c<<""<<endl;
        cout<<"Checking!"<<endl;
    }
};

int main()
{
    A *a1 = new A;
    B *b1 = new B;
    cout<<a1->a<<""<<a1->b<<""<<a1->c<<""<<endl;
    b1->a=10;
    b1->b=20;
    b1->c=30;
    cout<<b1->a<<""<<b1->b<<""<<b1->c<<""<<endl;

    b1->get();//cant able to change the variables of the base class object with the derived class object
    cout<<a1->a<<""<<a1->b<<""<<a1->c<<""<<endl;//will print the same values..

    //b1->get();

    return 0;
}

output:

000
102030
102030
Checking!
000
Press any key to continue . . .

//The address of the variables that is holded by the derived class object is different from the address of the variables that is holded by the base class object.Isnt..
//But is there any possiblity to change the variables of the base class through the derived class object..

  • 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-21T16:41:15+00:00Added an answer on May 21, 2026 at 4:41 pm

    In your get() method, you are actually creating a temporary instance of Base class A, which has nothing to do with the class getting derived. Simply remove a2 from everywhere in your get() and try it. You will be able to see the changes happening.

    [Note: Base class object is automatically allocated when derived object is allocated. That means when you do new B, it will allocate memory for B and A]

    Edit:

    For your question, your get() should be like this:

    void get()
    {
        a=10;
        b=20;
        c=30;
        cout<<a<<b<<c<<endl;
        cout<<"Checking!"<<endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual
#include stdafx.h #include <iostream> using std::cout; template<class T> class IsPolymorphic { template<class T> struct
#include <iostream> using namespace std; int main() { double u = 0; double w
#include<iostream> class name { public: int a; name():a(0){}; }; void add(name * pname) {
#include iostream class A { private: int a; public : A(): a(-1) {} int
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
// Huffman Tree.cpp #include stdafx.h #include <iostream> #include <string>//Necessary to do any string comparisons
I have a C++ program representing a TCP header as a struct: #include stdafx.h
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits

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.