2021-7-8-&-二级指针-this指针-SeqStack

一、&的作用

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cassidy *

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值