Call to implicitly deleted copy constructor

Hi,

I’m trying to have a std::vector of a class I’ve defined, but I keep on getting the error: Call to implicitly deleted copy constructor. It says that the copy constructor is implicitly deleted because of a user-declared move constructor, but I haven’t done anything like that. The same thing occurs when I use a unique_ptr of the class.

It looks like it might be because: 13. Copy assignment operator of 'Booper' is implicitly deleted because field 'soundOscillator' has a deleted copy assignment operator (soundOscillator is a juce::dsp::Oscillator, and a member of Booper, the class which I want to have a vector of).

Any ideas what to do about this?

Thank you!

Seems the soundOscillator is not copyable.
The copy assignment operator is deleted.
This could for instance be because you added the
JUCE_DECLARE_NON_COPYABLE or JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR macros.

It is also the case if you inherit a class where this macro was used, which is the case for every juce::Component and many others.
And it is the case for any class, that has a member where the copy constructor was deleted, including std::unique_ptrs and std::atomic, unless you created a bespoke copy constructor, that deals with those members and create a clean copy if that is applicable for your use case.

When you assign a std::unique_ptr into a std::vector, you have to tell that the pointee shall be moved into the constructor, which in turn will invalidate the previous std::unique_ptr:

auto thing = std::make_unique<Thing>(); // thing has now a valid instance
std::vector<std::unique_ptr<Thing>> things;
things.push_back (std::move (thing)); // the Thing that thing was pointing to is now in the vector
thing->foo(); // not allowed, because thing is now empty

unique_ptr means, the Thing can only be owned at one place.

1 Like

That makes sense, I tried it out and it did the trick. I’m still fairly new to C++ and not very familiar with this sort of thing yet, so thank you very much for the help!