T
terminator800tlgm
I don't understand the difference between ojbect handle and reference.
For example,
class Stack
{
private:
CD cd_obj; // cd object
DVD & dvd_ref;// dvd reference
Why is it that dvd_ref can ONLY be initialized in the Stack's
constructor whereas cd_obj can be initialized during the Stack
object's lifetime?
Also, why is not allowed to return by reference a locally created
object?
For example,
Vector Vector:perator+(const Vector & b) const
{
return Vector(x+b.x, y+b.y); //Why is this allowed?
}
Vector & Vector:perator+(const Vector & b) const
{
return Vector(x+b.x, y+b.y); //Why is this NOT allowed?
}
For example,
class Stack
{
private:
CD cd_obj; // cd object
DVD & dvd_ref;// dvd reference
Why is it that dvd_ref can ONLY be initialized in the Stack's
constructor whereas cd_obj can be initialized during the Stack
object's lifetime?
Also, why is not allowed to return by reference a locally created
object?
For example,
Vector Vector:perator+(const Vector & b) const
{
return Vector(x+b.x, y+b.y); //Why is this allowed?
}
Vector & Vector:perator+(const Vector & b) const
{
return Vector(x+b.x, y+b.y); //Why is this NOT allowed?
}