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 ...
随机推荐
- 错误21002:[SQL-DMO]用户"xxx"已经存在
原文:错误21002:[SQL-DMO]用户"xxx"已经存在 转载自:http://topic.csdn.net/u/20120829/09/faf381b6-d4e9-4f97 ...
- React.js入门笔记 创建hello world 的6种方式
一.ReactJS简介 React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设 Instagram 的网站. ...
- JEECG移动解决方案 -
针对移动应用的应用系统转换的中间件解决方案
设想: 通过中间件配置,在业务系统中使用到移动应用程序的简单版本.(移动页面生成器) 实现方法: 当前移动应用解决方式非常多:app?html5?微信 採用何种方法来实现?对于一个企业来讲,app分 ...
- 10624 - Super Number
题目链接 题意:给出n到m的范围,求出一个数在前i位数组成的数字能被i整除.假设存在输出这个数,假设不存在.输出-1. 思路:回溯,每次放第i位,然后推断是否符合题意.这题踩着时间过去的2.6s(看了 ...
- 【Eclipse高速发展-文章插件】google V8,对于调试Nodejs
安装的的时候能够通过 Help>Eclipse Marketplace的 搜索方式安装 或者 Help>Install New Software Name:googleV8 Locatio ...
- cocos2dx 使得单麻将(三)
cocos2dx 使得单麻将(三) 麻将逻辑4.得到手牌数据 我们已经保存了一个一维数组, 类似于一个表格,统计出全部牌相应的数量, 但我们如何得到当前手中是什么牌呢 //扑克转换 BYTE Swit ...
- String.Format in Java and C#
原文:String.Format in Java and C# JDK1.5中,String类新增了一个很有用的静态方法String.format(): format(Locale l, String ...
- hadoop编程小技巧(7)---自己定义输出文件格式以及输出到不同文件夹
代码測试环境:Hadoop2.4 应用场景:当须要定制输出数据格式时能够採用此技巧,包含定制输出数据的展现形式.输出路径.输出文件名称称等. Hadoop内置的输出文件格式有: 1)FileOutpu ...
- 写作Openwrt固件
启动tftp软体.并设置文件夹的固件文件(Current Dircctory)和serverIP(Service interface).server指PC机.图.: ...
- JavaEE(19) - Web层和EJB的整合(Session Bean)
1. 通过依赖注入访问无状态Session Bean #1. EJB注入Servlet中 #2. EJB注入JSF中 2. 通过EJB引用访问有状态Session Bean 3. 在工具类中访问Ses ...