lundi 27 avril 2015

Compilation failure associated with vector of const std::string

Please can someone explain why the following code doesn't compile using clang 3.5.

The error reported is 'No viable overloaded '=' in algorithm.'

std::vector<const std::string> m_messages;
std::vector<const std::string>::iterator iter;
...

if (iter != m_messages.end())
{
    m_messages.erase(iter);      // compilation error
}

If I declare m_messages as: std::vector<std::string> m_messages; then it compiles OK.

Also, what is the difference between:

std::vector<const std::string> m_messages;

and

std::vector<std::string> m_messages;

TIA.

Aucun commentaire:

Enregistrer un commentaire