/*
- test.cpp
*
- Created on: 2013-8-16
- Author: xiaohun
*/
include <iostream>
using namespace std ;
class Vector3D {
public:
float x,y,z;
public:
Vector3D(){
x=y=z=0;
};
Vector3D(float x,float y,float z){
this->x=x;this->y=y;this->z=z;
};
void print(char* v);
static Vector3D& Add1(Vector3D& v1,Vector3D& v2,Vector3D& v);
static Vector3D& Add2(Vector3D* v1,Vector3D* v2,Vector3D* v);
static Vector3D* Add3(Vector3D& v1,Vector3D& v2,Vector3D& v);
static Vector3D* Add4(Vector3D* v1,Vector3D* v2,Vector3D* v);
static Vector3D& Add5(Vector3D& v1,Vector3D& v2);
static Vector3D& Add6(Vector3D* v1,Vector3D* v2);
static Vector3D* Add7(Vector3D& v1,Vector3D& v2);
static Vector3D* Add8(Vector3D* v1,Vector3D* v2);
};
/**
- 返回输出变量的引用,输入参数和输出参数都为引用
*/
Vector3D& Vector3D::Add1(Vector3D& v1,Vector3D& v2,Vector3D& v){
v.x=v1.x+v2.x;
v.y=v1.y+v2.y;
v.z=v1.z+v2.z;
return v;
}
/**
- 返回输出变量的引用,输入参数和输出参数都为指针
*/
Vector3D& Vector3D::Add2(Vector3D v1,Vector3D v2,Vector3D* v){
v->x=v1->x+v2->x;
v->y=v1->y+v2->y;
v->z=v1->z+v2->z;
return *v;
}
/**
- 返回输出变量的指针,输入参数和输出参数都为引用
*/
Vector3D* Vector3D::Add3(Vector3D& v1,Vector3D& v2,Vector3D& v){
v.x=v1.x+v2.x;
v.y=v1.y+v2.y;
v.z=v1.z+v2.z;
return &v;
}
/**
- 返回输出变量的指针,输入参数和输出参数都为指针
*/
Vector3D Vector3D::Add4(Vector3D v1,Vector3D v2,Vector3D v){
v->x=v1->x+v2->x;
v->y=v1->y+v2->y;
v->z=v1->z+v2->z;
return v;
}
/**
- 返回局部变量的引用(局部变量的引用作为输出),输入参数为引用,没有输出参数
*/
Vector3D& Vector3D::Add5(Vector3D& v1,Vector3D& v2){
Vector3D* v=new Vector3D();
v->x=v1.x+v2.x;
v->y=v1.y+v2.y;
v->z=v1.z+v2.z;
return *v;
}
/**
- 返回局部变量的引用(局部变量的引用作为输出),输入参数为指针,没有输出参数
*/
Vector3D& Vector3D::Add6(Vector3D v1,Vector3D v2){
Vector3D* v=new Vector3D();
v->x=v1->x+v2->x;
v->y=v1->y+v2->y;
v->z=v1->z+v2->z;
return *v;
}
/**
- 返回局部变量的指针(局部变量的指针作为输出),输入参数为引用,没有输出参数
*/
Vector3D* Vector3D::Add7(Vector3D& v1,Vector3D& v2){
Vector3D* v=new Vector3D();
v->x=v1.x+v2.x;
v->y=v1.y+v2.y;
v->z=v1.z+v2.z;
return v;
}
/**
- 返回局部变量的指针(局部变量的指针作为输出),输入参数为指针,没有输出参数
*/
Vector3D Vector3D::Add8(Vector3D v1,Vector3D* v2){
Vector3D* v=new Vector3D();
v->x=v1->x+v2->x;
v->y=v1->y+v2->y;
v->z=v1->z+v2->z;
return v;
}
void Vector3D::print(char* v){
for(int i=0;i<=8;i++){
cout<<"第"<<i+1<<"次v=("<<this->x<<","<<this->y<<","<<this->z<<")"<<this<<endl;
}
}
/**
- 返回输出变量的引用,输入参数和输出参数都为引用
*/
void func1(){
cout<<"返回输出变量的引用,输入参数和输出参数都为引用"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D v;
Vector3D::Add1(v1,v2,v);
v.print("v");
}
/**
- 返回输出变量的引用,输入参数和输出参数都为指针
*/
void func2(){
cout<<"返回输出变量的引用,输入参数和输出参数都为指针"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D v;
Vector3D::Add2(&v1,&v2,&v);
v.print("v");
}
/**
- 返回输出变量的指针,输入参数和输出参数都为引用
*/
void func3(){
cout<<"返回输出变量的指针,输入参数和输出参数都为引用"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D v;
Vector3D::Add3(v1,v2,v);
v.print("v");
}
/**
- 返回输出变量的指针,输入参数和输出参数都为指针
*/
void func4(){
cout<<"返回输出变量的指针,输入参数和输出参数都为指针"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D v;
Vector3D::Add4(&v1,&v2,&v);
v.print("v");
}
/**
- 返回局部变量的引用(局部变量的引用作为输出),输入参数为引用,没有输出参数
*/
void func5(){
cout<<"返回局部变量的引用(局部变量的引用作为输出),输入参数为引用,没有输出参数"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D v;
v=Vector3D::Add5(v1,v2);
v.print("v");
}
/**
- 返回局部变量的引用(局部变量的引用作为输出),输入参数为指针,没有输出参数
*/
void func6(){
cout<<"返回局部变量的引用(局部变量的引用作为输出),输入参数为指针,没有输出参数"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D v;
v=Vector3D::Add6(&v1,&v2);
v.print("v");
}
/**
- 返回局部变量的指针(局部变量的指针作为输出),输入参数为引用,没有输出参数
*/
void func7(){
cout<<"返回局部变量的指针(局部变量的指针作为输出),输入参数为引用,没有输出参数"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D* v=new Vector3D();
v=Vector3D::Add7(v1,v2);
v->print("v");
}
/**
- 返回局部变量的指针(局部变量的指针作为输出),输入参数为指针,没有输出参数
*/
void func8(){
cout<<"返回局部变量的指针(局部变量的指针作为输出),输入参数为指针,没有输出参数"<<endl;
Vector3D v1(2,3,4);
Vector3D v2(1,2,3);
Vector3D* v=new Vector3D();
v=Vector3D::Add8(&v1,&v2);
v->print("v");
}
int main(){
func1();
func2();
func3();
func4();
func5();
func6();
func7();
func8();
return 0;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。