临时对象

//
// @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

posted @ 2016-01-11 23:34  vtudiv  阅读(122)  评论(0编辑  收藏  举报