T
Tony Johansson
Hello!!
Assume I have a wrapper class with this definition.
class Integer
{
public:
Integer(int =0);
int get() const;
Integer& set(int);
Integer& add(const Integer&);
private:
int value_;
};
I have also some stand-alone functions se below
Now to my question the function createZero is returning an Integer object
lets call this object temp.
This temp object is received as a reference in function yuk. No copy
constructor is called therefore.
So does this mean that when yuk is eventually finishing the temp object goes
out of scope.
So the assignment from function foo to object g will be invalid because of
temp is out of scope.
//Tony
Integer createZero()
{ return Integer(0); }
const Integer& yuk(const Integer& i)
{ return i; }
void foo()
{
const Integer& g = yuk(creteZero());
cout << g.value();
}
Assume I have a wrapper class with this definition.
class Integer
{
public:
Integer(int =0);
int get() const;
Integer& set(int);
Integer& add(const Integer&);
private:
int value_;
};
I have also some stand-alone functions se below
Now to my question the function createZero is returning an Integer object
lets call this object temp.
This temp object is received as a reference in function yuk. No copy
constructor is called therefore.
So does this mean that when yuk is eventually finishing the temp object goes
out of scope.
So the assignment from function foo to object g will be invalid because of
temp is out of scope.
//Tony
Integer createZero()
{ return Integer(0); }
const Integer& yuk(const Integer& i)
{ return i; }
void foo()
{
const Integer& g = yuk(creteZero());
cout << g.value();
}