T
Tony Johansson
Hello!!
Assume you have the following AccountForStudent class
class AccountForStudent
{
public:
AccountForStudent (long, double);
~AccountForStudent ;
long getNumber() const
private:
Student * stud_;
double balance_;
};
and you have a stand alone function equal defined as
bool equal(AccountForStudent as, long number)
{ return as->getNumber() == number; }
// and you instansiate an object kasia of class AccountForStudent in this
way
AccountForStudent kasia(100, 200);
//and you call this function equal in this way
if (equal(kasia,200))
. . . .
Now to my question I just want to check with you that I have understood it
right.
When this function equal is called the copy constructor is used to
initialize object as using kasia.
Now the object as and kasia are sharing the Student object. When the
function equal finish and the object as goes out of scope the destructor for
object as is called and in the destuctor is the object Student deleted.
This will cause the kasia object to have no valid Student object any longer.
//Tony
Assume you have the following AccountForStudent class
class AccountForStudent
{
public:
AccountForStudent (long, double);
~AccountForStudent ;
long getNumber() const
private:
Student * stud_;
double balance_;
};
and you have a stand alone function equal defined as
bool equal(AccountForStudent as, long number)
{ return as->getNumber() == number; }
// and you instansiate an object kasia of class AccountForStudent in this
way
AccountForStudent kasia(100, 200);
//and you call this function equal in this way
if (equal(kasia,200))
. . . .
Now to my question I just want to check with you that I have understood it
right.
When this function equal is called the copy constructor is used to
initialize object as using kasia.
Now the object as and kasia are sharing the Student object. When the
function equal finish and the object as goes out of scope the destructor for
object as is called and in the destuctor is the object Student deleted.
This will cause the kasia object to have no valid Student object any longer.
//Tony