C
cfchou
hi, all,
i'm reading ch.20 -smart pointers- of [C++ Template].
and i'm tring the trule.hpp test. but there's something different
than i expect, and i found that's about temp object. so i simplified
the question into the following code:
===code starts===
#include <iostream>
using namespace std;
class H
{
public:
H(int i){ cout << "h" << endl; }
};
class T
{
public:
T(int i){ cout << "t" << endl; }
T(H& h){ cout << "ht" << endl; }
T(T const & rhs){ cout << "tt" << endl; }
};
T foo()
{
int i = 10;
return i;
}
T bar()
{
H h(11);
return h;
}
int main()
{
T t1(foo());
T t2(bar());
return 0;
}
===code ends===
on my win2k box, i both use bcb and devc++ to test it:
===bcb output===
t
tt
h
ht
tt
===devc++ output===
t
h
ht
=============
well, i though bcb was right, cause both foo() and bar() generate
temp obj, and which should be use to copy contruct the return T.
anyway, i want to know which is correct, i mean, std compliant.
if it's not bcb, why?
thanks.
i'm reading ch.20 -smart pointers- of [C++ Template].
and i'm tring the trule.hpp test. but there's something different
than i expect, and i found that's about temp object. so i simplified
the question into the following code:
===code starts===
#include <iostream>
using namespace std;
class H
{
public:
H(int i){ cout << "h" << endl; }
};
class T
{
public:
T(int i){ cout << "t" << endl; }
T(H& h){ cout << "ht" << endl; }
T(T const & rhs){ cout << "tt" << endl; }
};
T foo()
{
int i = 10;
return i;
}
T bar()
{
H h(11);
return h;
}
int main()
{
T t1(foo());
T t2(bar());
return 0;
}
===code ends===
on my win2k box, i both use bcb and devc++ to test it:
===bcb output===
t
tt
h
ht
tt
===devc++ output===
t
h
ht
=============
well, i though bcb was right, cause both foo() and bar() generate
temp obj, and which should be use to copy contruct the return T.
anyway, i want to know which is correct, i mean, std compliant.
if it's not bcb, why?
thanks.