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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:12:18+00:00 2026-05-13T13:12:18+00:00

Suppose i have a base class person. and i publically inherits a class student

  • 0

Suppose i have a base class “person”. and i publically inherits a class “student ” from the base class “person”. i have not written the copy constructor for base and the derived class. now suppose i write in the main program

main()
{
student sobj1("name", "computer science");
student sobj2=sobj1;
}

now in the second line the default compiler generated copy constructor of the student will be called but before the execution the default copy constructor of the base class will be called which creates an anonymous object and initialize it then control comes back to the copy constructor of the student which initialize the student’s portion of the object.

this is the demonstration for the situation where we don’t write the copy constructor
now suppose we write the copy constructor for both the classes , then i have tested that when i write

student sobj2=sobj1;

what happens is , this line calles the copy constructor of the student which works , but the copy constructor of the bases class will not be called in this case(default constructor of the base class will be called) my question is why?

  • 1 1 Answer
  • 3 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-13T13:12:18+00:00Added an answer on May 13, 2026 at 1:12 pm

    I believe the rules are following:

    1. Constructor of base class always should be called before constructor of derived class.
    2. You can choose which one of base class constructors will be called by calling it explicitly in initialization list.
    3. If you do not do that, default constructor is called.
    4. When class has no copy constructor, compiler generates one instead. It will call default constructors for all the members of the class and copy constructor of base class, just as your hand written constructor actually should.

    So, there you go. Unless you call copy constructor of base class, default one will be used BUT compiler is smart enough to actually call it in it’s own generated copy constructor.

    Just in case you do not know how to call it, there example

    Student(Student const & p): Person(p) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a Base class and a Child class that inherits from Base
Suppose I have a base class and two classes derived from it: class Base
Suppose I have a class derived from a base class. Polymorphism allows me to
Suppose I have a Base class and its derived class Derived as follows: class
Suppose I have a class Dog that inherits from a class Animal . What
Suppose I have class Base and Derived : public Base . I have constructed
Suppose I have a base and derived class: class Base { public: virtual void
Suppose I have a base class Person and I publicly inherit a class Teacher
Suppose I have 1 base class and a derived class. The derived class has
Suppose I have a Base & Derived class: class Base{ private: int* _privateIntPtrB; protected:

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.