object C—类中函数的调用
Object C—类中函数的调用
创建,三个类。然后,在代码中调用相同名字的函数。观察他们的调用次序。
@interface test : NSObject
- (void)print;
@end
@implementation test
- (void)print{
NSLog(@"test0");
}
@end
@interface test1 : test
- (void)print;
@end
@implementation test1
- (void)print{
NSLog(@"test1");
}
@end
@interface test2 : test
- (void)print;
@end
@implementation test2
- (void)print{
NSLog(@"test2");
}
@end
我们创建了三个类,然后在下面使用。
test1 *test11 = [[test1 alloc] init];
[test11 print];
test2 *test22 = [[test2 alloc] init];
[test22 print];
test *test00;
test00 = test11;
[test00 print];
输出结果:
2015-05-22 14:00:41.858 test[1034:75692] test0
2015-05-22 14:00:41.858 test[1034:75692] test2
2015-05-22 14:00:41.858 test[1034:75692] test0
总结:在函数预编译的时候,test00认为调用print函数为test类申明中的函数,但是在真正编译的时候,发现这个test00指针指向了一个test11(test1类的实例),因此,按照函数方法从子类向父类搜索的性质来看,这个方法调用的是test1中的实现方法。
object C—类中函数的调用的更多相关文章
- MFC浅析(7) CWnd类虚函数的调用时机、缺省实现
CWnd类虚函数的调用时机.缺省实现 FMD(http://www.fmdstudio.net) 1. Create 2. PreCreateWindow 3. PreSubclassWindow 4 ...
- 梳理:python—同一个类中的方法调用
为什么突然在此提到这个梳理问题呢? 因为在自己实践综合练习学过的知识时,突然觉得有些知识点的运用总是不成功,于是翻过课本进行回顾,总是觉得是对的,可是当再进一步思考“既然是对的,为什么在程序中总是不成 ...
- 深入理解类成员函数的调用规则(理解成员函数的内存为什么不会反映在sizeof运算符上、类的静态绑定与动态绑定、虚函数表)
本文转载自:http://blog.51cto.com/9291927/2148695 总结: 一.成员函数的内存为什么不会反映在sizeof运算符上? 成员函数可以被看作是类 ...
- 关于js中函数的调用问题
js中函数的调用方法 1.直接调用 函数名(参数): 2.通过指向函数的变量去调用 例如: var myval = 函数名: 此刻 myval是指向函数的一个指针: myval(实际参数):此刻调用的 ...
- JavaScript中函数的调用
JavaScript中函数的调用 制作人:全心全意 在JavaScript中,函数定义后并不会自动执行,要执行一个函数需要在特定的位置调用该函数,调用函数需要创建调用语句,调用语句包含函数名称和参数. ...
- Spring @Cacheable注解 && 事务@Transactional 在同一个类中的方法调用不生效
@Cacheable 注解在对象内部调用不会生效 代码示例:ProductServiceImpl.java public List<ProductInfoVO> getProductLis ...
- JavaScript中函数的调用!
JavaScript中函数的调用! 1 普通函数 // 1 普通函数 function fn() { console.log(123); } // 函数名 + 一个小括号! 或者 函数名.call() ...
- C语言中函数的调用方式
第一眼看到这样一个题目的我,心想除了如下的直接调用还能怎么调用呢? 1 void fun(void) 2 { 3 ...... 4 //你的代码 5 ..... 6 } 7 int main(void ...
- @Transactional-同一个类中方法自调,调用方法事物失效
问题分析 一个类中的方法调用另一个事物传播性为创建事物的方法,调用的方法事物失效? SpringAOP 代理的Service对象调用了其方法,这个方法再去调用这个Service中的其他方法是没有使用A ...
随机推荐
- 正确安装 django-socketio
直接使用 pip 安装,连 example project 都运行不了... 要正常使用,关键是要使用正确版本的依赖包 Django (1.5.5) django-socketio (0.3.2) g ...
- "git add -A" is equivalent to "git add .; git add -u".
git add -A stages All git add . stages new and modified, without deleted git add -u stages modified ...
- 4537: [Hnoi2016]最小公倍数
Description 给定一张N个顶点M条边的无向图(顶点编号为1,2,…,n),每条边上带有权值.所有权值都可以分解成2^a*3^b的形式.现在有q个询问,每次询问给定四个参数u.v.a和b,请你 ...
- Laravel之路——事务
准备: 表必须是InnoDB引擎 DB::beginTransaction(); try{ $name = 'abc'; $result1 = Test::create(['name'=>$na ...
- JDK源码阅读(二) AbstractList
package java.util; public abstract class AbstractList<E> extends AbstractCollection<E> i ...
- theano中的logisticregression代码学习
1 class LogisticRegression (object): 2 def __int__(self,...): 3 4 #定义一些与逻辑回归相关的各种函数 5 6 def method1( ...
- Codeforces Round #204 (Div. 2): B
很简单的一个题: 只需要将他们排一下序,然后判断一下就可以了! 代码: #include<cstdio> #include<algorithm> #define maxn 10 ...
- A simple brute force problem.
hdu4971:http://acm.hdu.edu.cn/showproblem.php?pid=4971 题意:给你n个项目,每完成一个项目会有一定的收益,但是为了完成某个项目,要先学会一些技能, ...
- python手记(32)
#!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...
- [LeetCode#274]H-Index
Problem: Given an array of citations (each citation is a non-negative integer) of a researcher, writ ...