Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ vector compile error, when using vector::push_back() method
    text
    copied!<p>I'm using std::vector in my program and I get this error when compiling:</p> <blockquote> <p>/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc: In member function `User&amp; User::operator=(const User&amp;)':</p> <p>/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:238: instantiated from <code>void std::vector&lt;_Tp, _Alloc&gt;::_M_insert_aux(__gnu_cxx::__normal_iterator&lt;typename _Alloc::pointer, std::vector&lt;_Tp, _Alloc&gt; &gt;, const _Tp&amp;) [with _Tp = User, _Alloc = std::allocator&lt;User&gt;]' /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:564: instantiated from</code>void std::vector&lt;_Tp, _Alloc>::push_back(const _Tp&amp;) [with _Tp = User, _Alloc = std::allocator]'</p> <p>main.cpp:100: instantiated from here</p> <p>/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:238: error: non-static const member `const std::string User::NAME', can't use default assignment operator</p> </blockquote> <p>I have classes "User" and "Users":</p> <pre><code>class User { public: const string NAME; User(const string &amp;name, const bool &amp;isMain = false) : NAME(name), isMain(isMain) {}; void addFollower(User * user); void addReplier(User * user, const int &amp;count); void addMentioner(User * user, const int &amp;count); void addRetweeter(User * user, const int &amp;count); private: vector&lt;User *&gt; followedBy, repliedBy, mentionedBy, retweetedBy; vector&lt;int&gt; replyCount, mentionCount, retweetCount; bool isMain; }; class Users { public: vector&lt;User&gt; users; void addUser(const string &amp;name, bool isMain = false); User * findUser(const string &amp;name); friend ostream &amp; operator &lt;&lt;(ostream &amp;outStream, const Users &amp;users); User &amp; operator [] (unsigned int index); }; </code></pre> <p>Here is the thing. The error is caused by the method Users::addUser():</p> <pre><code>void Users::addUser(const string &amp;name, bool isMain) { User newUser(name, isMain); users.push_back(newUser); } </code></pre> <p>If I erase the second line</p> <pre><code>users.push_back(newUser); </code></pre> <p>it works fine, but well, it doesn't work as like as you see because it prevents me from adding new records into the "users" vector array. I'll be thankful if anyone tells me what is the cause. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload