一、&的作用
1.char c = a & b; 位与
2.char* cp = &a; 取地址
3.char & x = a; 引用
二、二级指针
int main()
{
int a = 10;
int b = 20;
int* p = &a;
int** s = NULL;
s = &p;
*s = &a;
**s = 100;
*s = &b;
**s = 200;
}
p = &a;
*p => a;
&s ==> 0x; s => &p; *s => &p;
**s => *p => a;
三、面向对象的概念
计算机世界 现实世界
对象————————————映射————————————实体
| |
实 分析
例 和
化 抽象
| |
类————————————设计————————————抽象类别(主观世界)
四、this指针
1.识别和记录类体中的属性的名称,类型和访问限定,与属性在类体中的位置无关。如class CGoods 中的Name,Amount ,Price。
2.识别和记录类体中的函数原型(返回类型+函数名+参数列表),形参的默认值,访问限定。不识别函数体。
3.改写在类中定义函数的参数列表和函数体,改写对象调用成员函数的形式。
四.构造函数的任务
1.创建对象,并且对对象的成员初始化
2·构造函数返回构建对象的地址析构函数
五、SeqStack 栈
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#include<iostream>
using namespace std;
template<class Type>
class SeqStack
{
private:
Type* data;
int maxsize;
int top;
public:
SeqStack(int sz = 10) :maxsize(sz), top(-1)
{
data = (Type*)malloc(sizeof(Type) * maxsize);
if (data == NULL) exit(1);
}
~SeqStack()
{
free(data);
data = NULL;
maxsize = 0;
top = -1;
}
int GetSize() const { return top + 1; }
bool Is_Empty() const { return GetSize() == 0; }
bool Is_Full() const { return GetSize() ==
maxsize; }
bool Push(const Type& x)
{
if (Is_Full()) return false;
data[++top] = x;
return true;
}
Type& GetTop()
{
return data[top];
}
const Type& GetTop() const
{
return data[top];
}
void Pop()
{
--top;
}
void Clear()
{
top = -1;
}
};
int main()
{
SeqStack<int> ist = SeqStack<int>();
ist.Push(12);
ist.Push(23);
ist.Push(34);
ist.Push(45);
while (!ist.Is_Empty())
{
int x = ist.GetTop();
ist.Pop();
cout << x << endl;
}
return 0;
}