Note that there are some explanatory texts on larger screens.

plurals
  1. POCompiler error when adding an object to a vector
    text
    copied!<p>Why do I get the following compiler error when adding an object to a vector, which its data member is referencing another object?</p> <p>The compiler error:</p> <p>Error 1 error C2582: 'operator =' function is unavailable in 'Product' c:\program files\microsoft visual studio 8\vc\include\xutility 2726</p> <p>In the program I collect all data before I create a new Product object,</p> <p>then, creating the object and passing all data to the constructor:</p> <p>the problem is in the push_back(p) line,</p> <pre><code>vector&lt;Product&gt; productsArr; vector&lt;string&gt; categoriesArr; class Product { private: string m_code; string m_name; string&amp; m_category_ref; string m_description; double m_price; Product(); public: Product(const string&amp; code,const string&amp; name,string&amp; refToCategory, const string&amp; description, const double&amp; price):m_category_ref(refToCategory) { m_code = code; m_name = name; m_description = description; m_price = price; } } void addProduct() { string code,name,description; double price; int categoryIndex; getProductData(code,name,price,categoryIndex,description); Product p(code,name,categoriesArr[categoryIndex],description,price); productsArr.push_back(p); } </code></pre> <p>the line from the xutility:</p> <pre><code>// TEMPLATE FUNCTION fill template&lt;class _FwdIt, class _Ty&gt; inline void __CLRCALL_OR_CDECL _Fill(_FwdIt _First, _FwdIt _Last, const _Ty&amp; _Val) { // copy _Val through [_First, _Last) _DEBUG_RANGE(_First, _Last); for (; _First != _Last; ++_First) *_First = _Val; } </code></pre>
 

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