匿名对象的深入分析
来源:互联网 发布:郑州丰泽教育编程 编辑:程序博客网 时间:2024/05/01 21:08
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Location
{
public:
Location(int xx = 0, int yy = 0)
{
X = xx;
Y = yy;
cout << "Constructor Object.\n";
}
Location(const Location &p)
{
X = p.X;
Y = p.Y;
cout << "Copy_constructor called." << endl;
}
~Location()
{
cout << X << "," << Y << " Object destroyed." << endl;
}
int getx()
{
return X;
}
int gety()
{
return Y;
}
private:
int X, Y;
};
void f(Location p)
{
cout << "Funtion:" << p.getx() << "," << p.gety() << endl;
}
Location g()
{
Location A(1, 2);
return A;
}
void mainobjplay()
{
//Location B;
//B = g();//40 =等号操作
Location B = g();
f(B);
cout << "Funtion:" << B.getx() << "," << B.gety() << endl;
//42 对象初始化操作 直接将g()返回的匿名对象转变为B对象,匿名对象会新开辟新的内存空间,应该存在栈区,但不知道。
//如果返回的匿名对象,来初始化另外一个同类型的类对象,那么匿名对象会直接转成新的对象。。。
//匿名对象的去和留,关键看,返回时如何接过来。
cout << "测试测试" << endl;
}
void main()
{
mainobjplay();
system("pause");
}
#include<iostream>
using namespace std;
class Location
{
public:
Location(int xx = 0, int yy = 0)
{
X = xx;
Y = yy;
cout << "Constructor Object.\n";
}
Location(const Location &p)
{
X = p.X;
Y = p.Y;
cout << "Copy_constructor called." << endl;
}
~Location()
{
cout << X << "," << Y << " Object destroyed." << endl;
}
int getx()
{
return X;
}
int gety()
{
return Y;
}
private:
int X, Y;
};
void f(Location p)
{
cout << "Funtion:" << p.getx() << "," << p.gety() << endl;
}
Location g()
{
Location A(1, 2);
return A;
}
void mainobjplay()
{
//Location B;
//B = g();//40 =等号操作
Location B = g();
f(B);
cout << "Funtion:" << B.getx() << "," << B.gety() << endl;
//42 对象初始化操作 直接将g()返回的匿名对象转变为B对象,匿名对象会新开辟新的内存空间,应该存在栈区,但不知道。
//如果返回的匿名对象,来初始化另外一个同类型的类对象,那么匿名对象会直接转成新的对象。。。
//匿名对象的去和留,关键看,返回时如何接过来。
cout << "测试测试" << endl;
}
void main()
{
mainobjplay();
system("pause");
}
0 0
- 匿名对象的深入分析
- 深入分析类与对象--构造方法与匿名对象
- 【javase复习】##day2 对象的内存分析、匿名对象 ##
- java中匿名对象分析
- java中匿名对象分析
- 类的匿名对象
- Java的匿名对象
- 匿名对象的使用
- 匿名对象的使用
- 匿名对象的使用
- 匿名对象的使用
- 匿名对象的Distinct
- java的匿名对象
- java的匿名对象
- 匿名对象的生命周期
- 匿名对象的使用:
- 深入分析C++的对象实现
- 深入分析Java对象的建构顺序
- J2SE-选择排序法初识
- 去掉标题栏的JFrame如何实现拖动
- Linux下源码安装mysql及mysql的简单用法
- Java并发编程:volatile关键字解析
- Android NDK开发 在eclipse中添加C方法代码提示
- 匿名对象的深入分析
- Android的sax解析xml
- java4Android(20):类集框架->Set/Map/List->ArrayList简单实例
- springMVC(12) springMVC和spring集成
- 顺序容器vector-用法1
- IOS开发之实现App消息推送
- 买卖股票最多K次
- linux C 遍历目录及其子目录 opendir -> readdir -> closedir http://blog.csdn.net/angle_birds/article/details/
- 2015长春网赛