【COMP282 LEC1 and LEC2】

LEC 1

1. Printf 在C++中的写法

 2. Header file

1. 不能写 “.h”

2. strlen变成.size() 

3. Namespace

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

4.  Input

就是input是std::cin >>

 LEC 2

1. Classes

2. 3 access modifiers in C++

 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

4. Split between .h and .cpp

 5. Constructors and Destructors

6. Adding a constructor and destructor

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)

2. Slicing

#

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

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 : 

Permanent objects: 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值