操作符重载
来源:互联网 发布:高中数学软件 编辑:程序博客网 时间:2024/06/05 19:07
#ifndef _VERTEX_H_
#define _VERTEX_H_
class Vertex
{
public:
Vertex(float x, float y, float z):px(x),py(y),pz(z){}
Vertex(){}
float px;
float py;
float pz;
Vertex operator+(const Vertex &p);
Vertex operator-(const Vertex &p);
void operator=(Vertex &p);
};
#define _VERTEX_H_
class Vertex
{
public:
Vertex(float x, float y, float z):px(x),py(y),pz(z){}
Vertex(){}
float px;
float py;
float pz;
Vertex operator+(const Vertex &p);
Vertex operator-(const Vertex &p);
void operator=(Vertex &p);
};
#endif
#include "Vertex.h"
Vertex Vertex::operator +(const Vertex &p)
{
Vertex temp;
temp.px = px + p.px;
temp.py = py + p.py;
temp.pz = pz + p.pz;
return temp;
}
Vertex Vertex::operator -(const Vertex &p)
{
Vertex temp;
temp.px = px - p.px;
temp.py = py - p.py;
temp.pz = pz - p.pz;
return temp;
}
void Vertex::operator =(Vertex &p)
{
px = p.px;
py = p.py;
pz = p.pz;
}
#include <iostream>
#include "Vertex.h"
using namespace std;
#include <iostream>
#include "Vertex.h"
using namespace std;
int main()
{
Vertex v1(1.0f, 2.0f, 3.0f);
cout<<v1.px<<v1.py<<v1.pz<<endl;
Vertex v2 = v1;
cout<<v2.px<<v2.py<<v2.pz<<endl;
Vertex v3;
v3 = v1 + v2;
cout<<v3.px<<v3.py<<v3.pz<<endl;
getchar();
return 1;
}
- c++重载操作符
- C++ 操作符重载
- 操作符重载浅析
- 操作符重载
- 10.8 操作符重载
- 操作符重载
- 操作符重载手册
- C#操作符重载
- 操作符重载手册
- 操作符重载手册
- 六操作符重载
- 操作符的重载
- C#操作符重载
- 多态,操作符重载
- 操作符重载集锦
- 重载操作符
- 操作符重载
- 操作符重载手册
- Android截图以及加水印Demo
- java 线程池
- 编译源码生成的SDK,创建android project 没有proguard.cfg问题
- IE8访问应用表单提示‘拒绝访问’
- 如何查看进程打开了哪些文件?---linux下的proc文件系统
- 操作符重载
- 输入一个字符串,输出该字符串的最长重复子序列。
- 离线iOS应用的HTML 5制作指南
- struts2.0中struts.xml配置文件详解
- Open Inventor练习-SoElapsedTime引擎作用
- cPanel设置:防盗链/远程MySQL/泛域名解析/禁止IP
- 系统设计中业务规则与系统规则的应用
- 吸塑与吹塑工艺介绍
- 苦逼的日期控件自绘