当前位置: 首页 > news >正文

【COMP282 LEC3 LEC4 LEC5】

LEC 3 

Overloading 超载

1. Two functions can have the same name if they have different parameters

2. The compiler will use the one whose parameters match the ones you pass in

Performing Addition “+”

重载一个operator + ,这个operator+函数被定义为ruler类的成员函数

1. temp是一个新的ruler常量用来储存相加后的结果

2. feet和inches分别表示是英尺和英寸,类似磅和便士,(但是12英寸=1英尺)所以是this的feet和ru的feet相加,this的inches和ru的inches相加

Comparison Operators "<" ">"

这种重载作用大概就是指本来"==","<",">"有定义了,但是引入了英寸和英尺两个单位,所以重新定义这三个比较符号

LEC 4

Unary and binary operators

There are 3 types of operators:

  Prefix-unary, postfix-unary and binary

    E.g. -a would be prefix-unary, a++ would be postfix-unary and a+b would be binary

前缀一元运算符,后缀一元运算符,二元运算符

Templates 模版?

In overloading, we provide multiple implementations of the same function for different parameters

With templates, we provide one implementation that behaves similarly for different parameters (still implementing one function)

Class templates

为了解决返回多个objects的问题?

LEC 5

standard template library

Contains three main parts:

1. Containers: standard data structures

2. Iterators: standard ways to move through the standard data structures

3. Algorithms: uses iterator(s) (usually 2 and often some method as parameters) to give their results

Example containers : Vectors

Vector is essentially automatic resizing array 自动调整数组size

vector<int> is roughly equal to ArrayList<Integer> in Java 

Vector access

Containers 

1. Vector:

automatic resizing arrays (i.e. O(1) for accessing/updating elements and adding to the end – adding elements elsewhere cost O(n))

2. Arrays:

arrays (same complexity) Faster than vector due to less overhead

3. Deques:

More advanced automatic resizing array that allows inserting/deleting at the start as well in O(1) time Slower and have more overhead than vector

4. Set and map (and their multi- variants):

balanced trees (O(log n) accessing/updating/adding/removing elements)

5. List:

doubled-linked list (O(1) traversing/updating/adding/removing elements – can’t really access)

6. Forward_list:

single-linked list

Example container: Multiset (Multiset is essentially a balanced tree)

Things are stored in ascending order (based on <) by default

You can do it with other orderings, but it looks a bit ugly… 

Multiset access:

Iterators 迭代器是用于访问/操作其容器中的数据的对象

Iterators are objects for accessing/manipulating the data in their container Multiple levels of them:

Random access, bidirectional, forward, input = output

(Input and output are at the same level)

Syntax looks a little strange so we need to explain it

 1. Multiset/vector class has a member object called iterator

 2. In this example, the multiset/vector template is using integers

 3. So the iterator will point to an integer within the multiset/vector

Inserting/deleting using iterators

 

Iterator invalidation

这里it4是没有明确指代的 不能用auto it4 = store2.end();

而应该重新定义it4 :it4 = store2.end();

再去比较

STL Arrays

可以用function

http://www.lryc.cn/news/132599.html

相关文章:

  • panda3d加载模型复习和python面向对象编程属性学习
  • 使用 Node.js 生成优化的图像格式
  • 【WinAPI详解】<CreateWindowEx详解>
  • 【Git】分支管理
  • 玩转单元测试之gtest
  • Tomcat 一次请求的生命周期
  • spring cloud gateway中配置uri
  • 使用NAudio录制wav音频
  • 数据结构之动态内存管理机制
  • 【汇编语言】栈及栈操作的实现
  • 【JavaEE】面向切面编程AOP是什么-Spring AOP框架的基本使用
  • SpringBoot+微信小程序奶茶在线点单小程序系统 附带详细运行指导视频
  • 【支付宝小程序】开发基础--文件结构教程
  • LLM 生成式配置的推理参数温度 top k tokens等 Generative configuration inference parameters
  • npm的镜像源和代理的查看和修改
  • IP库新增经过实践的Verilog 库
  • SLAM-VIO视觉惯性里程计
  • 分布式 RPC 框架入门
  • Spring boot与Spring cloud 之间的关系
  • 报名开启 | HarmonyOS第一课“营”在暑期系列直播
  • Apache DolphinScheduler 支持使用 OceanBase 作为元数据库啦!
  • matlab使用教程(17)—广度优先和深度优先搜索
  • CSerialPort教程4.3.x (2) - CSerialPort源码简介
  • 【数据结构OJ题】有效的括号
  • Java性能分析中常用命令和工具
  • JVM性能分析-jstat工具观察gc频率
  • mysql 查询报错 1267 - Illegal mix of collations
  • 【ARM】Day6
  • 深入理解Flink Mailbox线程模型
  • Docker搭建LNMP运行Wordpress平台