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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:31:07+00:00 2026-05-29T07:31:07+00:00

In Deitel C++ book (C++11 for Programmers, p.286) , there is an example of:

  • 0

In Deitel C++ book (“C++11 for Programmers”, p.286) , there is an example of:

class Date { ... }

class Employee {
public:
   Employee(const string &, const string &, const Date &, const Date &);
private:
    string firstName;
    string lastName;
    const Date birthDate;
    const Date hireDate;
}

Employee::Employee( const string &first, const string &last, 
   const Date &dateOfBirth, const Data &dateOfHire)
   : firstName( first),
     lastName( last),
     birthDate(dateOfBirth),
     hireDate(dateOfHire) { };

The book says the member initializer such as birthDate(dateOfBirth) invoked Date class’s copy constructor. I am confused as to why copy constructor? I thought the whole point of “pass by reference” is to avoid the object copy?

If I do:

Date birth(7,24, 1959);
Date hire(2,12, 1988);
Employer staff("bob", "blue", birth, hire);

How many Date objects does the system have now, 2 or 4? (Two created at the start, two are created by copy constructor)

  • 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-29T07:31:08+00:00Added an answer on May 29, 2026 at 7:31 am

    It is not the passing mode that involves a copy.

    It is the initialization of the members that involve a copy (obviously? the parameters don’t live in the class, and the class members need to get the same value: copy)

    Let’s examine

    Employee::Employee(const string& first, const string& last,
                       const Date& dateOfBirth, const Data& dateOfHire)
        : firstName(first)
        , lastName(last)
        , birthDate(dateOfBirth)
        , hireDate(dateOfHire) { }
    
    int main() {
        const std::string fname = "test";
        Employee e(fname, /* ..... */);
    }
    
    1. We invoke Employee::Employee, passing fname by const& (no copy).
    2. The constructor initializes it’s member firstname from the first parameter
    3. This exercises std::string(const std::string&), again passing the parameter on by const& (still no copy).
    4. The std::string copy constructor now takes all necessary steps to copy the the value of it’s parameter into the object itself. This is the copy

    It makes sense that when you construct a new std::string (in this case as a member of Employee), it results in a … new std::string. Thinking of it this way makes it very easy to grasp, I think.

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

Sidebar

Related Questions

I found an example from a c# book as follows: <text:directory xmlns:text = urn:deitel:textInfo
I'm reading my Deitel, Java How to Program book and came across the term
I'm learning C++ with this book of Deitel: C++ How to Program, 5/e and
This is out of deitel's c++ book and I'm trying to understand a bit
I am working on Ajax examples from a book and the example from the
I have a problem import java.math.BigInteger; import java.io.*; import java.util.*; import java.lang.*; public class
I'm trying to do another exercise from Deitel's book. The program calculates the monthly
I'm C++ begginer. I did this excercise from Deitel's book: Use a one-dimensional array
I was reading my C++ book (Deitel) when I came across a function to
I'm trying to understand this code from Deitels 5th edition c book. If I'm

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.