B
Barry
Hi all,
I'm learning C++ and am currently trying to get my head around memory
leakage.
I have a class, C, which contains a number of vectors, as follows -
vector<A> a;
vector<B> b;
I'm trying to implement an assignment operator for this class which is
exception safe and am wondering if the following meets this criteria
and if I'm doing it correctly -
C& C:perator=(const C& c)
{
C temp(c);
temp.swap(*this);
return *this;
}
void C::swap (C &c) throw ()
{
std::swap(this->a,c.a);
std::swap(this->b,c.b);
}
Thanks very much for your help,
Barry.
I'm learning C++ and am currently trying to get my head around memory
leakage.
I have a class, C, which contains a number of vectors, as follows -
vector<A> a;
vector<B> b;
I'm trying to implement an assignment operator for this class which is
exception safe and am wondering if the following meets this criteria
and if I'm doing it correctly -
C& C:perator=(const C& c)
{
C temp(c);
temp.swap(*this);
return *this;
}
void C::swap (C &c) throw ()
{
std::swap(this->a,c.a);
std::swap(this->b,c.b);
}
Thanks very much for your help,
Barry.