我知道一些基本概念,如复制构造函数和其他 c++ 概念,如下例所示
#include<iostream>
#include<stdio.h>
using namespace std;
class Test
{
public:
Test() {}
Test(const Test &t)
{
cout<<"Copy constructor called "<<endl;
}
Test& operator = (const Test &t)
{
cout<<"Assignment operator called "<<endl;
}
};
int main()
{
Test t1, t2;
t2 = t1;
Test t3 = t1;
getchar();
r
eturn 0;
}
现在,当我试图在办公室中理解项目的代码流时,但我正在为此苦苦挣扎。我无法弄清楚流程如何进行。有时我得到了一些概述,但是当我深入研究代码时,我没有将c ++概念连接到实际代码。
代码流如下所示:
-
Test t1, t2
t1、t2 将被构造,但没有提供参数,因此调用默认构造函数,不输出任何内容。 - 调用运算符 =
t2 = t1
,输出Assignment operator called
-
t3 = t1
t3 将被构造,并且 t1 作为参数提供,因此调用复制构造函数,输出Copy constructor called
另外,将stdio.h
更改为 cstdio
,C++使用 cstdio
而不是 stdio.h