2021-07-10

#include <iostream>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include<stdio.h>
using namespace std;

int main()
{
	int a = 10, b = 20;

	int* p = &a;
	*p = 100;
	p = &b;

	const int* cp = &a;//修饰*,*cp不能改,指向不能改,不能通过*cp改变a
	*cp = 100;
	cp = &b;

	int* const s = &a;//s自身不能变,但可通过*cp改变a的值
	*s = 100;
	s = &b;

	const int* const p = &a;//p自身不能改,*p指向的值也不能改
	*p = 100;
	p = &b;
}
#include <iostream>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include<stdio.h>
using namespace std;
typedef class Type;

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);
	}
	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;
	}
	~SeqStack()//析构函数,释放
	{
		free(data);
		data = NULL;
		maxsize = 0;
		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;
}
#include <iostream>
using namespace std;

class Int
{
	int value;
public:
	Int(int x = 0) :value(x)
	{
		cout << "Creat Int:" << this << endl;
	}
	Int (const Int& it)
	{
		cout << "Copy Creat Int:" << this << endl;
	}
	~Int()
	{
		cout << "Destroy Int:" << this << endl;
	}
};

int main()
{
	Int a(10);
	Int b(a);
	return 0;
}

1.函数重载:

同一作用域中声明几个类似的同名函数,其形参列表不同用以处理实现功能类似数据类型不同的问题
2.名字粉碎技术:

用于函数重载(函数名相同),编译器在编译的时候给函数起了新名字(?函数名@@YA返回类型 两个形参的类型@Z)
3.

①.new是运算符,自动计算所需空间的大小,内存(堆区-3G)不足时,抛出异常【调用构造函数,delete】
malloc是函数调用,自己计算,内存不足返回空指针【free】
②.new的底层是调用malloc,malloc的底层是调用tip malloc

realloc   扩充之前分配的内存块
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值