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 ...
随机推荐
- Cocos2d-x 3.1.1 学习日志16--A星算法(A*搜索算法)学问
A *搜索算法称为A星算法.这是一个在图形平面,路径.求出最低通过成本的算法. 经常使用于游戏中的NPC的移动计算,或线上游戏的BOT的移动计算上. 首先:1.在Map地图中任取2个点,開始点和结束点 ...
- Android应用启动还有一个应用
已知包名和应用入口Activity 包名:org.ww 应用入口:Activity:org.ww.TestActivity Intent intent = new Intent(); intent.s ...
- HDU ACM 1290 献给杭电五十周年校庆的礼物
解析: 1.n条直线把平面切割成的区域数为: f(n)=f(n-1)+n=n(n+1)/2+1; 2.把空间切割为最多区域数的时候,第n个平面与前(n-1)个平面相交.且无三面共线,因此该平面与前(n ...
- window.open的小技巧分享(转)
今天再次谈起window.open是因为发现了一个比较好玩的小技巧,详细内容我们稍后详细说明. 聊到window.open,不得不说明一下他的使用方法,主要有两种形式: window. ...
- POJ 3280 间隔DP
字符串,每次插入或删除字符需要一定的价格,问:我怎样才能使这个字符串转换成字符串回文,花最少. 间隔DP 当DP到区间[i,j+1]时,我们能够在i-1的位置加入一个str[j+1]字符,或者将在j+ ...
- spring mvc 控制器方法传递一些经验对象的数组
由于该项目必须提交一个表单,其中多个对象,更好的方法是直接通过在控制器方法参数的数组. 因为Spring mvc框架在反射生成控制方法的參数对象的时候会调用这个类的getDeclaredConstru ...
- Rational Rose 2007使用小结
1.Rose怎样隐藏类的属性和操作? 右击类,选Options->Suppress Attributes/Suppress Operations 2.Rose怎样表示类的约束? 在工具箱中选AB ...
- Web 服务器 (IIS) 角色
原文:Web 服务器 (IIS) 角色 1. 对于默认安装,请在命令行提示符下键入以下命令,然后按 Enter: start /w pkgmgr /iu:IIS-WebServerRole;WAS-W ...
- HDU 4085 Steiner树模板称号
Dig The Wells Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- EXCEL 两人的建立Y轴
在本文中,EXCEL2013基于,操作的其他版本基本上相同模式 原始数据和最后的结果如下面的: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvanloX2p ...