Thread: How actually is a derived class implementation on inheritance ?

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    8

    How actually is a derived class implementation on inheritance ?

    How actually is a derived class implementation on inheritance, as class is just abstract.
    E.g.
    Code:
    class A {public: int x;};
    class B : public A {int y;};
    Does a B object instantly "realize" having A member.

    Code:
    int main()    {
    
    A a;
    B b;
    a.x =7;
    b.x += 3;   // How is inheritance supposed to be?
                     // how will be b.x =10?
    
    }

  2. #2
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    307
    B derives public-ly from A. That roughly saying "B is of type A" AND "B has its own set of properties that may differ from A". Why don't you run the code yourself and check if b.x is 10? Is it 10 though? Try it Just add this to your code tho (so that you don't have uninitialised value usage):

    Code:
    class A {public: int x = 0;};
    class B : public A {int y = 0;};
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. derived destructor problem in inheritance
    By cena06 in forum C++ Programming
    Replies: 4
    Last Post: 01-02-2014, 07:31 PM
  2. Replies: 7
    Last Post: 11-18-2012, 11:17 AM
  3. Replies: 8
    Last Post: 03-19-2008, 03:04 AM
  4. Inheritance: assign base class to derived class
    By MWAAAHAAA in forum C++ Programming
    Replies: 15
    Last Post: 01-22-2007, 04:31 PM
  5. Replies: 1
    Last Post: 12-11-2002, 10:31 PM

Tags for this Thread