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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:09:39+00:00 2026-05-28T17:09:39+00:00

#include <iostream> int main(void) { class date { private: int day; int month; int

  • 0
#include <iostream>


int main(void)
{

class date {
private:
  int day;
  int month;
  int year;
public:
  date( )  { std::cout << "default constructor called" << std::endl; }
  date& operator=(const date& a) { std::cout << "copy constructor called" << std::endl; day=a.day; month=a.month; year=a.year; }
  date(int d ,int m ,int y  ) : day(d),month(m),year(y){ std::cout << "constructor called" << std::endl; }
  void p_date(){ std::cout << "day=" << day << ",month=" << month  << ",year=" << year << std::endl; }
  date& add_day(int d) { day += d; return  *this;}
  date& add_month(int d) { month += d;return  *this; }
  date& add_year(int d) { year += d;return  *this; }

};

class cdate {
  date n;
public:
   cdate(date b) : n(b)  { std::cout << "cdate constructor called" << std::endl;}
   void p_cdate() { n.p_date(); }
};

  cdate ncdate(date(30,1,2012));
  ncdate.p_cdate();
}

When we instantiate ncdate in this code:

  1. temporary date object created when we call cdate ncdate(date(30,1,2012));
  2. then i expect the call n = b and expect n‘s copy constructor to be called.

n‘s copy constructor is not getting called and i cant figure out why. I know there is something wrong in the 2nd assumption. Note: this is test code only so don’t go over its performance, usability etc.

  • 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-28T17:09:39+00:00Added an answer on May 28, 2026 at 5:09 pm

    You have not defined a copy constructor for date, so the implicitly-declared copy constructor is used.

    A copy constructor would look like date(date const& other) { }. You have provided a default constructor (date()) and a copy assignment operator (date& operator=(const date& a)). Neither of these is the copy constructor.

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

Sidebar

Related Questions

#include <iostream> namespace { int a=1; } int a=2,b=3; int main(void) { std::cout<<::a<<::b; return
include stdafx.h #include <iostream> using namespace std; class Foo{ public: void func() { cout<<Hello!!<<endl;
#include <iostream> using namespace std; int main (void) { cout << 1\t2\t3\t4\t5\t6\t7\t8\t9 << endl
#include iostream using namespace std; class A { public: void mprint() { cout<<\n TESTING
#include <iostream> #include <vector> using namespace std; int main(void) { int i, s, g;
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
#include <iostream> using namespace std; int main() { cout << !!!Hello World!!! << endl;
#include <iostream> using namespace std; int main() { double u = 0; double w
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
#include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open

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.