【COMP282 LEC 1-2】

news2024/9/27 12:10:05

LEC 1 Introduction to c++

Header file :

1. 不用写 " .h "

Function : 

数据类型有string了,就像java,需要#include<string>

Output system :

Explain by example:

std::cout << hello << " is of length " << x;

std::cout means standard character output

<< means insertion (so we insert into std::cout) – each of them inserts into the left most

  It must be by types supporting <<

all standard types does support << and we will later in the course see how to add this feature in our own classes

The rest are strings or numbers We can insert as many as we would like

It looks better than printf, because we do not need to have that format string first

Namespace

std::bla says that bla is in the standard namespace

Namespace is like packages in java

E.g. std::cout means cout as it is defined in the std namespace and std::endl means endl as it is defined in the std namespace

Input system : 

Input is done by writing std::cin >> bla;

  When we have a std::string called bla

  It waits until a line has been written and insert the part upto the first space in bla

LEC 2

C++ classes

>> Classes in C++ is an option – not a requirement

>> If you do not like classes, you can simply not write any in C++

  You can still get things like nicer strings and/or nicer input in/output

  Some small programs are written like that…

  Take the features you like, avoid the features you do not…

就像上面那张图一样,class的后括号要加一个分号,这一点不太一样

 Access modifiers in C++

>> There are three access modifiers in C++ : private(default), public, protected

>> Most is the same as Java

>>The syntax is different from Java: You write e.g. public: and then a list of declarations and they are all public 不是写在类的那一行的前面,而是在括号里面

Example : 

Getters and Setters 

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

Constructors and Destructors

Constructors in C++ behave the same as they do in Java

  >> Called whenever an object is created  

  >> Has no return type and must have the same name as the class

  >> Performs any setup required by the class (such as memory allocation) 

  >> If you don’t declare a constructor then a default one will be used

  >> If you do declare one, the default one will get removed

Java does not have destructors because it uses garbage collection

  >> Objects are automatically deleted when no longer in use

  >> Memory is freed and tidied up automatically

In C++ the destructor is called whenever an object is deleted

  >> Has the same name as the class with a tilde in front of it

  >> Should free up any memory and resources allocated by the constructor 应该释放构造函数分配的内存和资源

Memory Management in C++

Member Initialisation

Inheritence

Like in Java, but with different syntax

Child classes inherit variables and methods of their parent

Difference: There are no interfaces though 没有接口

Difference: C++ has access modifiers on inheritance  访问修饰符

 

Polymorphism(多态性):

首先dog类继承了父类animal类,他继承了父类的方法“makeNoise”。在main里,创建了一个dog类叫“rover”

?????

Virtual Polymorphism: 

Remember that C++ is used for coding low-level device drivers, embedded systems, etc.

1. Needs to generate small, memory efficient, fast executable code

2. Polymorphism adds complexity and size to the finished product

3. So, the compiler only does it when we explicitly ask for it

Initialisation:

 

 

Slicing:分割

1. 定义了一个方法:“output” 作用就是打印出一个格式,比如说这里就是

Fluffy weighs 5 and has lives 9

2. 把子类的data(fluffy) pass to 了父类animal(pet)

Accessing child through parent: 

The three ways to pass objects to functions: 

 

结果:

rover weighs 8

fluffy weighs 0

Permanent objects:​​​​​​​ 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/439042.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

电脑IP地址查询,3个实用方法!

案例&#xff1a;电脑IP地址怎么查询 【请问有没有朋友知道电脑IP地址怎么查询呀&#xff1f;想看看我的IP地址却不知道该怎么查询&#xff0c;哪位友友可以帮帮我&#xff01;】 在互联网世界中&#xff0c;IP地址是一种用于标识设备&#xff08;如电脑、手机等&#xff09;…

在OLED上显示各种各样的数据(文字、字母、图片)

今天来说一说OLED&#xff0c;也同时记录一下成果。 在学习OLED之前需要知道IIC协议&#xff0c;不了解的可以看&#xff08;IIC协议相关_dxdlnu的博客-CSDN博客&#xff09; 什么是OLED? OLED_百度百科 (baidu.com) 一.OLED写入指令和数据 因为OLED是有写入指令/数据的操作…

camunda工作流引擎多租户架构

Camunda支持多租户的方式有两种&#xff1a;共享引擎和多引擎。 1、共享引擎 在共享引擎的模式下&#xff0c;多个租户共享同一个Camunda引擎。每个租户的数据被存储在引擎中的不同表中&#xff0c;而引擎的配置和部署是共享的。可以通过以下方式实现共享引擎&#xff1a; &…

OpenAI-ChatGPT最新官方接口《微调ChatGPT模型》全网最详细中英文实用指南和教程,助你零基础快速轻松掌握全新技术(四)(附源码)

微调ChatGPT模型 前言Introduction 导言What models can be fine-tuned? 哪些模型可以微调&#xff1f;Installation 安装Prepare training data 准备训练数据CLI data preparation tool CLI数据准备工具Create a fine-tuned model 创建微调模型Use a fine-tuned model 使用微…

​HTTP和TCP协议的队头阻塞​

队头阻塞&#xff08;Head-of-line blocking&#xff09;其实有两种&#xff0c;一种是 TCP 队头阻塞&#xff0c;另一种是 HTTP 队头阻塞&#xff0c;而这两者之前其实还存在一定的联系&#xff0c;毕竟 HTTP1/2 是建立在 TCP 协议之上的应用层协议&#xff0c;另外还有HTTP3对…

【LeetCode 图论 一】初探有向图Directed Graph

今天主要介绍DAG &#xff08;Directed acyclic graph&#xff09;&#xff0c;有向无环图。 无向图的问题相对有向图比较简单&#xff0c;比如岛屿问题&#xff0c;迷宫问题等。 在有向图中&#xff0c;我们通常只关注环是否存在&#xff0c;因为有向图中环的存在会让我们的…

HBuilderX的快捷键 和 常见配置

快捷键说明ctrl /添加注释&#xff08;js&#xff1a;// 注释、css&#xff1a;/* 注释 */、vue/nvue模板&#xff1a; <!-- 注释 -->&#xff09;Ctrl C 拷贝当前行或者所选代码块到剪切板Ctrl X剪切当前行或所选代码块到剪切板Ctrl V粘贴剪切板上的内容Ctrl D 删除…

浏览器实时查看日志系统-log.io

标题 前言操作步骤1. Install server via npm安装Nodejs2. Launch server3. Install file input via npm4. Configure file input前言 log.io 是一个实时日志监控工具,采用 node.js + socket.io 开发,使用浏览器访问,每秒可以处理超过5000条日志变动消息。有一点要指出来的…

叔可忍婶不可忍!马斯克3月呼吁暂停人工智能,4月却创立TruthGPT

2018年马斯克退出了OpenAI团队。 2022年11月&#xff0c;ChatGPT在北美大陆问世。 2023年3月21日&#xff0c;马斯克在未来生命&#xff0c;签署并呼吁&#xff0c;暂停高级人工智能的研发。 2023年4月18日马斯克创立了TruthGPT。 同时&#xff0c;亚马逊&#xff0c;也创立了B…

提桶跑路转行到软件测试,鬼知道我经历了什么?很庆幸转行成功...

说来惭愧&#xff0c;我的大学不是985也不是211&#xff0c;不过地质学科群一直排名国内前几&#xff0c;2017年也藉由地质学学科评上了“双一流”。咱们土木工程跟着沾沾光&#xff0c;也能和别人吹吹牛逼&#xff0c;所以毕业后的工作基本上在省内是不愁的。 但是我还是低估了…

“全自主、全流程、全覆盖”2023实景三维新技术研讨会广州站圆满举行!

4月12日&#xff0c;由中国测绘学会、中国地理信息产业协会指导&#xff0c;广州省测绘学会主办&#xff0c;武汉大势智慧科技有限公司承办的全自主、全流程、全覆盖”2023实景三维新技术研讨会广州站在广州珠江宾馆隆重举行。 本次会议广东省测绘学会、地图院、测绘院、市城市…

ChatGPT促进中国大语言模型发展,底层标注数据质量成关键,景联文科技提供专业数据采集标注服务

自开年以来&#xff0c;ChatGPT的热浪带来了一场全民的科技狂欢&#xff0c;同时打开了业内对NLP发展的想象空间&#xff0c;拉开了大语言模型产业和生成式AI产业飞速发展的序幕。 海外市场中OpenAI、微软、谷歌、Meta等巨头都在积极争抢布局ChatGPT&#xff0c;中国市场中百度…

NIFI大数据进阶_NIFI的模板和组的使用-介绍和实际操作_创建组_嵌套组_模板创建下载_导入---大数据之Nifi工作笔记0022

然后我们来看一下如何操作模板 首先我们准备好了一个模板,叫做CsvToJSON这样一个模板文件了 然后我们再来看左下角有个上传模板 可以选择这个模板上传上来,然后,就可以在右侧找到,菜单,找到template,点击,来查看模板了 然后添加组,就是顶部的那个两个圆圈的组件拖过来以后用来…

android compiled_local_resources\debug\out‘ is not a readable directory.

需要删除android目录下的.gradle文件。如下文件即可&#xff1a;

PyTorch实战1:实现mnist手写数字识别

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f366; 参考文章&#xff1a;365天深度学习训练营-第P1周&#xff1a;实现mnist手写数字识别&#x1f356; 原作者&#xff1a;K同学啊|接辅导、项目定制 目录 一、 前期准备1. 设置GPU2. 导入数…

EPICS Archiver Appliance在Debian11 容器下安装文档

PC安装虚拟化平台趟坑记录 上面proxmox在pc上安装好之后&#xff0c;相关的后台开始搭建&#xff0c;首先是AA数据存档服务。 EPICS Archiver Appliance在Debian11下安装文档 上面文档是晓康整理的&#xff0c;还一直没空完整的按流程做一遍&#xff0c;正好就着proxmox平台在…

【MySQL | 进阶篇】08、InnoDB 引擎架构、事务原理及 MVCC 讲解

目录 一、逻辑存储结构 二、架构 2.1 概述 2.2 内存结构 2.2.1 Buffer Pool 2.2.2 Change Buffer 2.2.3 Adaptive Hash Index 2.2.4 Log Buffer 2.3 磁盘结构 2.3.1 System Tablespace 2.3.2 File-Per-Table Tablespaces 2.3.3 General Tablespaces 2.3.4 Undo T…

Hbase1.3:Hbase基础架构、Hbase基础架构角色:Master、Region Server、Zookeeper、HDFS

Hbase1.3&#xff1a;Hbase基础架构、Hbase基础架构角色&#xff1a;Master、Region Server、Zookeeper、HDFS Hbase基础架构Hbase基础架构角色1&#xff09;Master2&#xff09;Region Server3&#xff09;Zookeeper4&#xff09;HDFS Hbase基础架构 Hbase架构里面&#xff0…

ubuntu18.04手动安装网卡驱动,重启系统后,驱动消失的解决方案

ubuntu18.04手动安装网卡驱动&#xff0c;重启系统后&#xff0c;驱动消失的解决方案 文章目录 ubuntu18.04手动安装网卡驱动&#xff0c;重启系统后&#xff0c;驱动消失的解决方案 1.问题描述2.问题分析3.解决方案&#xff08;使用 Netplan 配置网络&#xff09; 参考&#x…

XXL-JOB介绍

一、介绍 1.1、什么是XXL-JOB XXL-JOB是一个分布式任务调度平台&#xff0c;用于解决分布式系统中定时任务执行问题 1.2、架构图 二、部署 2.1、源码部署 2.1.1、下载源码 gitee下载地址 github下载地址 2.1.2、初始化数据库 2.1.3、修改数据库配置 2.1.4、将xxl-job-admi…