Open alexey-malov opened 7 years ago
CMyStringList & CMyStringList::operator=(CMyStringList & other)
{
if (this != &other) // защита от неправильного самоприсваивания
{
CMyStringList tmp;
for (auto const & elem : other)
{
tmp.PushBack(elem);
}
std::swap(m_firstNode, tmp.m_firstNode);
std::swap(m_lastNode, tmp.m_lastNode);
m_size = tmp.m_size;
}
// по соглашению всегда возвращаем *this
return *this;
}
void DoSomething(const CMyStringList & lst)
{
CMyStringList lst2;
if (true)
{
lst2 = lst;
}
}
Код не компилируется
int main()
{
using namespace std;
CMyStringList lst;
lst.PushBack("one");
lst.PushBack("two");
lst.PushBack("three");
lst.PushBack("four");
lst.PushBack("two");
lst.Erase(++lst.begin());
for (auto & i : lst)
{
cout << i << endl;
}
return 0;
}