【COMP282 LEC1 and LEC2】

LEC 1

1. Printf 在C++中的写法

【COMP282 LEC1 and LEC2】_第1张图片

 2. Header file

1. 不能写 “.h”

2. strlen变成.size() 

【COMP282 LEC1 and LEC2】_第2张图片

3. Namespace

前面用了“using namespace std;” 后面就可以直接写cout 不用写std::cout了

【COMP282 LEC1 and LEC2】_第3张图片

4.  Input

就是input是std::cin >>

【COMP282 LEC1 and LEC2】_第4张图片

 LEC 2

1. Classes

【COMP282 LEC1 and LEC2】_第5张图片

2. 3 access modifiers in C++

【COMP282 LEC1 and LEC2】_第6张图片

【COMP282 LEC1 and LEC2】_第7张图片

 3. Getters & Setters

1. Generally we don’t want to expose internal variables to the outside world, so we keep them private and define getters and setters

        We do not actually want to expose getters and setters either, except for cases (like here),    where we are using the class directly for data storage

【COMP282 LEC1 and LEC2】_第8张图片

4. Split between .h and .cpp

【COMP282 LEC1 and LEC2】_第9张图片

【COMP282 LEC1 and LEC2】_第10张图片

 5. Constructors and Destructors

【COMP282 LEC1 and LEC2】_第11张图片

6. Adding a constructor and destructor

【COMP282 LEC1 and LEC2】_第12张图片

【COMP282 LEC1 and LEC2】_第13张图片

7. Member Initialisation

A list of initialisations is inserted before the constructor body

在函数创造前,先列一个一个声明列表 

 Inheritence 继承

1.  和java的区别

Difference: There are no interfaces though  没有接口 

Difference: C++ has access modifiers on inheritance  访问修饰符(public private protected)

【COMP282 LEC1 and LEC2】_第14张图片

【COMP282 LEC1 and LEC2】_第15张图片

2. Slicing

【COMP282 LEC1 and LEC2】_第16张图片

【COMP282 LEC1 and LEC2】_第17张图片#

3. 转换 父类用子类的方法

【COMP282 LEC1 and LEC2】_第18张图片

4. The three ways to pass objects to functions

In C++ you can pass objects to functions in 3 ways (the first 2 are also in C and I assume you have seen them – still I will show examples):

  1. Directly (Like with C structures – the objects are copied)

  2. Pass a pointer (no copies are made)

  3. Pass by reference

Pass by reference is a simplification of pass by pointer approach

  1. The reference can’t be reassigned by the receiving method

  2. The syntax looks nicer because it uses the dot notation

  3. Effectively you are passing a pointer to an object

  4. Therefore, the original object is NOT copied

  5. Its content can be changed by the method and therefore any other pointers to the same object will see the changed version

Example : 

【COMP282 LEC1 and LEC2】_第19张图片

Permanent objects: 

【COMP282 LEC1 and LEC2】_第20张图片 

你可能感兴趣的:(算法)