自定义字符串类String,实现运算符重载,内存管理

1、String.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once
#include <iostream>
using namespace std;
 
class String {
	friend ostream &operator << (ostream &, String &);
private:
	char *m_name = NULL;
	char *setM_name(const char *cstring);
	char *strAppend(const char *, const char *);
public:
	String(const char *cstring = "");
	String(const String &);
	~String();
	bool operator == (String &string);
	String &operator = (String &string);
	String &operator = (const char *cstring);
	String operator + (const char *cstring);
	String operator + (const String &string);
	String &operator += (const char *cstring);
	String &operator += (const String &string);
	char operator[](int index);
	bool operator<(const String &string);
};
 
ostream &operator << (ostream &cout, String &string);
</iostream>

2、String.cpp

[……]

继续阅读

通过对象地址获取对象的虚函数列表

1、C++中多态是一种泛型编程思想,虚函数是实现这个思想的语法基础;

2、虚函数列表简称虚表,出现在对象的头部,即虚表的首地址即对象地址;

3、通过创建好的对象,可以得到虚表,从而通过偏移可获取所有虚函数的地址;

4、示例代码:

5、执行结果:

[……]

继续阅读

使用GCD封装一个简单的定时器

1、GCD定时器实现的基础代码

1
2
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, );
dispatch_source_set_timer(timer, DISPATCH_TIME[......]<p class="read-more"><a href="https://www.yusian.com/blog/project/2018/11/30/1106431446.html">继续阅读</a></p>

2、对其进行简单封装,使外部调用时传入间隔时间、重[……]

继续阅读

定时器NSTimer、CADisplayLink及代理NSProxy的基本使用

1、NSTimer常用的两种方式:scheduled与使用Runloop addTimer

1
2
[NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
    NSLo[......]<p class="read-more"><a href="https://www.yusian.com/blog/project/2018/11/29/1742151443.html">继续阅读</a></p>