• 10
• 10
• 12
• 12
• 14

# copy/move constructor and std::vector?

This topic is 537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

While developming my engine/ framework I've encountered the following situation:

- let's say I have class A: mySomethingClass and class B: mySomethingClassMgr

- class B has a member std::vector<mySomethingClass>

- I use the std::vector functions to use, fill and manage the std::vector in class B

But when I make the copy/ move constructors/assignment 'deleted'/ not allowed in class A, the std::vector functions don't work anymore, including "emplace_back".

//	CD3dShaderPack(const CD3dShaderPack& other) = delete;				// copy constructor: not allowed
//	CD3dShaderPack& operator=(const CD3dShaderPack& other) = delete;	// copy assignment: not allowed


mShaderPacks.emplace_back();

private:



My conclusion from this, is that "emplace_back" is somehow using a copy or move constructor/assignment.

The error I get when I not comment out the 4 lines above, is:

error C2280: 'Crealysm::D3DRENDERER::CD3dShaderPack::CD3dShaderPack(Crealysm::D3DRENDERER::CD3dShaderPack &&)': attempting to reference a deleted function
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0(857): note: see reference to function template instantiation 'void std::allocator<_Ty>::construct<_Objty,_Ty>(_Objty *,_Ty &&)' being compiled
1>          with
1>          [
1>          ]


When I comment out the 1st, 2nd and 4th and keep the 'copy assignment' = delete in place, it also works.

So it's a combination of the other 3 that gives the problem (tried all combinations, all 'NOK').

Do you know if there's a way to use the std::vector in class B with class A objects, without allowing copy/move constructor/assignment for class A?

Edited by cozzie