⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 指针使用.cpp

📁 c++实例~ 初学基础
💻 CPP
字号:
// 代码片段1
#include <iostream.h>

class M
{
public:
	M() { x=y=0; }
	M(int i, int j) { x=i; y=j; }
	void copy(M *m);
	void setxy(int i, int j) { x=i; y=j; }
	void print() { cout<<x<<","<<y<<endl; }
private:
	int x, y;
};

void M::copy(M *m)
{
	x=m->x;
	y=m->y;
}

void fun(M m1, M *m2);

void fun(M m1, M *m2)
{
	m1.setxy(12, 15);
	m2->setxy(22,25);
}

void main()
{
	M p(5, 7), q;
	q.copy(&p);
	fun(p, &q);
	p.print();
	q.print();
}


// 代码片段2
#include <iostream.h>

class M
{
public:
	M() { x=y=0; }
	M(int i, int j) { x=i; y=j; }
	void copy(M &m);
	void setxy(int i, int j) { x=i; y=j; }
	void print() {cout<<x<<","<<y<<endl; }
private:
	int x, y;
};

void M::copy(M &m)
{
	x=m.x;
	x=m.y;
}

void fun(M m1, M &m2);

void main()
{
	M p(5, 7), q;
	q.copy(p);
	fun(p, q);
	p.print();
	q.print();
}
void fun(M m1, M &m2)
{
	m1.setxy(12, 15);
	m2.setxy(22, 25);
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -