按值传递:
主调函数向调用函数传递参数实际上只是将实参的拷贝(即临时副本)传递给了被调用函数,并不是实参本身,这样被调函数不能直接修改主调函数中变量的值,而只能修改其私有的临时副本的值。
引用传递:
对引用的操作等于对其指定的对象进行操作,当将实参传递给形参时,形参就指向了实参
指针传递:
形参为指向实参地址的指针,当对形参的指向操作时,就相当于对实参本身进行的操作
#include <iostream>
#include<string>
using namespace std;
class human
{
public:
int age;
human(int inputage):age(inputage){}
};
/*void useage(human* newone)//指针传递
{
newone->age =1;
cout<<"hello,your age is "<<newone->age<<endl;
}
void useage(human& newone)//引用传递
{
newone.age =1;
cout<<"hello,your age is "<<newone.age<<endl;
}*/
void useage(human newone)//按值传递
{
newone.age =1;
cout<<"hello,your age is "<<newone.age<<endl;
}
//这几个又是静态多态???
int main()
{
human Harden(22);
cout<<Harden.age<<endl;
useage(Harden);
cout<<"hello,your age is "<<Harden.age<<endl;
return 0;
}