Note that there are some explanatory texts on larger screens.

plurals
  1. POcopy constructor not called
    primarykey
    data
    text
    <pre><code>#include &lt;iostream&gt; int main(void) { class date { private: int day; int month; int year; public: date( ) { std::cout &lt;&lt; "default constructor called" &lt;&lt; std::endl; } date&amp; operator=(const date&amp; a) { std::cout &lt;&lt; "copy constructor called" &lt;&lt; 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 &lt;&lt; "constructor called" &lt;&lt; std::endl; } void p_date(){ std::cout &lt;&lt; "day=" &lt;&lt; day &lt;&lt; ",month=" &lt;&lt; month &lt;&lt; ",year=" &lt;&lt; year &lt;&lt; std::endl; } date&amp; add_day(int d) { day += d; return *this;} date&amp; add_month(int d) { month += d;return *this; } date&amp; add_year(int d) { year += d;return *this; } }; class cdate { date n; public: cdate(date b) : n(b) { std::cout &lt;&lt; "cdate constructor called" &lt;&lt; std::endl;} void p_cdate() { n.p_date(); } }; cdate ncdate(date(30,1,2012)); ncdate.p_cdate(); } </code></pre> <p>When we instantiate <code>ncdate</code> in this code:</p> <ol> <li>temporary date object created when we call <code>cdate ncdate(date(30,1,2012));</code></li> <li>then i expect the call <code>n = b</code> and expect <code>n</code>'s copy constructor to be called. </li> </ol> <p><code>n</code>'s copy constructor is not getting called and i cant figure out why. I know there is something wrong in the 2nd assumption. <strong>Note:</strong> this is test code only so don't go over its performance, usability etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload