Pointers to classes (From the note of my firend)
Pointers to classes
Objects can also be pointed to by pointers: Once declared, a class becomes a valid type, so it can be used as the type pointed to by a pointer. For example:
|
|
is a pointer to an object of class Rectangle
.
Similarly as with plain data structures, the members of an object can be accessed directly from a pointer by using the arrow operator (->
). Here is an example with some possible combinations:
|
|
|
This example makes use of several operators to operate on objects and pointers (operators
*
, &
, .
, ->
, []
). They can be interpreted as:
expression | can be read as |
---|---|
*x |
pointed to by x |
&x |
address of x |
x.y |
member y of object x |
x->y |
member y of object pointed to by x |
(*x).y |
member y of object pointed to by x (equivalent to the previous one) |
x[0] |
first object pointed to by x |
x[1] |
second object pointed to by x |
x[n] |
(n+1 )th object pointed to by x |
Most of these expressions have been introduced in earlier chapters. Most notably, the chapter about arrays introduced the offset operator ([]
) and the chapter about plain data structures introduced the arrow operator (->
).
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Pointers to classes (From the note of my firend)的更多相关文章
- Leetcode 笔记 116 - Populating Next Right Pointers in Each Node
题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...
- LEETCODE —— Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...
- LeetCode OJ 116. Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
- LeetCode - Populating Next Right Pointers in Each Node
题目: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode ...
- 【leetcode】Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...
- 【leetcode】Populating Next Right Pointers in Each Node I & II(middle)
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
- [LeetCode]题解(python):116 Populating Next Right Pointers in Each Node
题目来源 https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ Given a binary tree ...
- 29. Populating Next Right Pointers in Each Node && Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node OJ: https://oj.leetcode.com/problems/populating-next-rig ...
- Populating Next Right Pointers in Each Node II--leetcode难题讲解系列
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
随机推荐
- MapReduce在实际编程“I/O”
通过本篇MapReduce分析模型.深化MapReduce理解模型:和演示MapReduc进入编程模型是常用格类型和输出格公式,在这些经常使用格外公式,我们能够扩大他们的投入格公式,实例:们须要把Mo ...
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- WP8关于对地图开发的改进
原文:WP8关于对地图开发的改进 微软在2012年6月21日 发布了 Windows Phone 8的更新.带来大量的功能更新和全新的SDK.作为重头戏的部分是引入了 C++ 和 DirectX,支持 ...
- Java 理论与实践: 正确使用 Volatile 变量(转)
Java 语言中的 volatile 变量可以被看作是一种 “程度较轻的 synchronized”:与 synchronized 块相比,volatile 变量所需的编码较少,并且运行时开销也较少, ...
- 基于Qt有限状态机的一种实现方式和完善的人工智能方法
基于Qt有限状态机的一种实现方式和完善的人工智能方法 人工智能在今年是一个非常火的方向,当然了.不不过今年,它一直火了非常多年,有关人工智能的一些算法层出不穷.人工智能在非常多领域都有应用,就拿我熟悉 ...
- matlab 图片批量读取
1. 指定的路径 单目录data所有图片 file_path = '.\data\';% 图片目录路径 img_path_list = dir(strcat(file_path,'*.jpg'));% ...
- POJ 3579- Median
Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of every pair of n ...
- 新秀nginx源代码分析数据结构篇(四)红黑树ngx_rbtree_t
新秀nginx源代码分析数据结构篇(四)红黑树ngx_rbtree_t Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csd ...
- css Tab选项卡1
利用 锚点原理 以及overflow:hiden 结合,实现纯 css tab 方式 兼容ie6 + 适合单个tab 不需要js 注意点 红色方框的 a 对应a ...
- CentOS7 安装NFS SSH免密码登陆
配置5台虚拟机 ip为192.168.1.160 - 164,使用160作为共享服务器 使用yum安装nfs 以及rpcbind,有很多文章介绍,这里不再赘述 一.启动服务 1.启动rpcbind s ...