Click here to Skip to main content
15,890,717 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionOperator overload question Pin
econy5-Apr-14 13:42
econy5-Apr-14 13:42 
AnswerRe: Operator overload question Pin
Richard Andrew x645-Apr-14 15:18
professionalRichard Andrew x645-Apr-14 15:18 
GeneralRe: Operator overload question Pin
econy7-Apr-14 5:49
econy7-Apr-14 5:49 
GeneralRe: Operator overload question Pin
Richard MacCutchan7-Apr-14 6:04
mveRichard MacCutchan7-Apr-14 6:04 
AnswerRe: Operator overload question Pin
CPallini7-Apr-14 2:28
mveCPallini7-Apr-14 2:28 
GeneralRe: Operator overload question Pin
econy7-Apr-14 5:51
econy7-Apr-14 5:51 
GeneralRe: Operator overload question Pin
CPallini7-Apr-14 6:21
mveCPallini7-Apr-14 6:21 
QuestionReference variable assignment and copy constructor call Pin
trinh.nguyen4-Apr-14 19:05
trinh.nguyen4-Apr-14 19:05 
I am testing the constructor call with the code below:

#include <iostream>

class A
{
public:
    A(int n = 0)
        : m_n(n)
    {

    }

    A(const A& a)
        : m_n(a.m_n)
    {

    }

private:
    int m_n;
};


int main()
{
    A a(2), b(1);

    const A c(a);

    const A &d = c;

    const A e = b; //Note 1

    b = d; //Note 2: I am confused here

    return 0;
}


Everything is OK with me.

But there is one point that I cannot understand is that: At the line "b = d" (Note 2), why the copy constructor is not called while at the line "const A e = b" (Note 2) the constructor is called?

I expect that at line Note 2, the copy constructor will be called to copy the value of "c" (referenced by "d") to "b", but it doesn't happen.

Please explain it, thank you in advance!
AnswerRe: Reference variable assignment and copy constructor call Pin
Randor 4-Apr-14 21:47
professional Randor 4-Apr-14 21:47 
GeneralRe: Reference variable assignment and copy constructor call Pin
trinh.nguyen4-Apr-14 23:10
trinh.nguyen4-Apr-14 23:10 
GeneralRe: Reference variable assignment and copy constructor call Pin
Randor 4-Apr-14 23:57
professional Randor 4-Apr-14 23:57 
QuestionSoftware USB write blocker for linux Pin
dream qq4-Apr-14 13:32
dream qq4-Apr-14 13:32 
QuestionHow to change tab event of property sheet Pin
kangte22223-Apr-14 15:15
kangte22223-Apr-14 15:15 
QuestionRe: How to change tab event of property sheet Pin
David Crow3-Apr-14 16:43
David Crow3-Apr-14 16:43 
AnswerRe: How to change tab event of property sheet Pin
Malli_S3-Apr-14 23:59
Malli_S3-Apr-14 23:59 
AnswerRe: How to change tab event of property sheet Pin
Randor 4-Apr-14 8:56
professional Randor 4-Apr-14 8:56 
QuestionGetWindowRect(),GetClientRect() question Pin
econy3-Apr-14 8:42
econy3-Apr-14 8:42 
AnswerRe: GetWindowRect(),GetClientRect() question Pin
Randor 3-Apr-14 9:08
professional Randor 3-Apr-14 9:08 
Questionsolar irradiance c++ program Pin
Member 107223713-Apr-14 6:53
Member 107223713-Apr-14 6:53 
AnswerRe: solar irradiance c++ program Pin
Albert Holguin3-Apr-14 7:00
professionalAlbert Holguin3-Apr-14 7:00 
GeneralRe: solar irradiance c++ program Pin
Member 107223713-Apr-14 7:13
Member 107223713-Apr-14 7:13 
AnswerRe: solar irradiance c++ program Pin
fat___boy3-Apr-14 10:25
fat___boy3-Apr-14 10:25 
Questionreading stdout Pin
Chris Losinger3-Apr-14 5:52
professionalChris Losinger3-Apr-14 5:52 
AnswerRe: reading stdout Pin
Albert Holguin3-Apr-14 7:05
professionalAlbert Holguin3-Apr-14 7:05 
GeneralRe: reading stdout Pin
Chris Losinger3-Apr-14 7:08
professionalChris Losinger3-Apr-14 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.