c++ 返回值是引用或者非引用
2014-02-07 09:40
197 查看
//============================================================================
// Name : TestReference.cpp
// Author :
// Version :
// Copyright : copy rigt
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Object.h"
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl;
Object o;
/* 0x22fe20
0x22fe10
0x22fe30*/
Object o1=o.retrunObject();
const Object &o2=o.retrunObject();
cout<<&o<<endl;
cout<<&o1<<endl;
cout<<&o2<<endl;
/* 0x22fe10
0x22fdf0
0x22fe10*/
Object o11=o.retrunReference();
Object &o22=o.retrunReference();
cout<<&o<<endl;
cout<<&o11<<endl;
cout<<&o22<<endl;
return 0;
}
// Name : TestReference.cpp
// Author :
// Version :
// Copyright : copy rigt
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Object.h"
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl;
Object o;
/* 0x22fe20
0x22fe10
0x22fe30*/
Object o1=o.retrunObject();
const Object &o2=o.retrunObject();
cout<<&o<<endl;
cout<<&o1<<endl;
cout<<&o2<<endl;
/* 0x22fe10
0x22fdf0
0x22fe10*/
Object o11=o.retrunReference();
Object &o22=o.retrunReference();
cout<<&o<<endl;
cout<<&o11<<endl;
cout<<&o22<<endl;
return 0;
}
相关文章推荐
- 20161224C++阶段班02_C to C++_03引用/指针/引用传参和返回值
- C++中的返回值引用
- C++返回值引用
- c++函数返回值与引用
- C++ 返回值为引用
- c++引用作为参数和返回值小结
- 20161224C++阶段班02_C to C++_03引用/指针/引用传参和返回值
- C++中返回引用和返回值的区别
- C++引用参数和引用返回值
- c++引用返回值
- c++引用参数与引用返回值
- 20161224C++阶段班02_C to C++_03引用/指针/引用传参和返回值
- C++引用(3) - 使用引用或者指针传递参数
- C++ 参数 返回值(引用)
- 20161224C++阶段班02_C to C++_03引用/指针/引用传参和返回值
- 正确使用C++引用做返回值和参数
- C++函数参数和返回值三种传递方式:值传递、指针传递和引用传递(着重理解)
- C++多态必须使用指针或者引用,直接传对象就变成切片
- 20161224C++阶段班02_C to C++_03引用/指针/引用传参和返回值
- C++ 成员函数返回引用,三种获取返回值的效果