0

Previously I had this:

vector<CThing>things;
void Add(const CThing & ins){ things.push_back(ins); }

Now I need to change the declaration because of slicing to:

vector<CThing*>things;

or

vector<unique_ptr<CThing>>;

But I am not sure how to implement the Add function...

I tried:

things.push_back(*ins); 

or

things.emplace_back(ins) 
Smeagol
  • 593
  • 9
  • 23
  • Do you understand how to apply the address of operator to get a pointer to an object? If not, then don't bother with `unique_ptr` and move semantics yet. – DeiDei Apr 22 '17 at 11:36
  • If you want the vector to take ownership, `std::unique_ptr` is the way to go. Your function should then take a already made `std::unique_ptr` as argument. – Unimportant Apr 22 '17 at 11:37
  • @DeiDei Ok, I won't, but I still don't know how to do that, the duplicate question got an answer that I should do "things.push_back(&ins); ". Am I right? But this gives me an error: candidate function not viable: no known conversion from 'const CThing' to 'const value_type' – Smeagol Apr 22 '17 at 11:53
  • You need to learn to produce [mcve]s. – juanchopanza Apr 22 '17 at 12:18

0 Answers0