SashaOcheev / OOP

0 stars 0 forks source link

Замечания по CStringList #11

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 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;
    }
}

Код не компилируется

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
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;
}