首页 > 其他 > 详细

临时对象

时间:2016-01-12 01:13:48      阅读:194      评论:0      收藏:0      [点我收藏+]
//
// @data 16-1-5 上午12:34
//

#include <iostream>

using namespace std;

class Test {
public:
    Test(const string & name,const int &age) : name(name),age(age){
        // no op
    }

    const string &name;
    const int &age;
};

int main(int argc, char *argv[]) {
    Test t1 = Test("hello",12);
    Test t2 = Test("world",13);

    cout << t1.name << "," << t2.name << endl;
    cout << &t1.name << "," << &t2.name << endl;
    cout << t1.age << "," << t2.age << endl;

    return 0;
}

world,world
0x7ffddff63c60,0x7ffddff63c60
-537510816,13

临时对象

原文:http://www.cnblogs.com/vtudiv/p/5122972.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!