C++ is a strong typed language, therefore you have to specify the type of elements that a std::vector
should hold as template argument. So in your case, this should be
std::vector<A> myVector;
If your vector is specified like that, you cannot e.g. add an integer like myVector.push_back (42);
because you created a vector explicitly intended to hold objects of type A
.
That being said, since C++ 17 you can under some circumstances drop the explicit template type, as class template argument deduction allows to automatically figure out the type when you assign values to it right away. Like
std::vector myVector { A(), A(), A() }; // will be deduced to myVector<A>
std::vector numbers { 42, 43, 44 }; // will be deduced to myVector<int>
But that usually only works when creating temporary vectors by assigning values directly to them, not when they are declared as empty vectors and elements are added later on.
Then you have chosen the wrong approach with your code above. If you do
A mNewInstance = A();
mSteps.push_back (mNewInstance);
Then mNewInstance
is created and in the call to push_back a copy of mNewInstance
is made and added to the vector. Now if you look at the juce_Component.h
source code you’ll find a JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Component)
which is a strong hint that copying objects of type juce::Component
is not possible, which then also applies to types derived from juce::Component
.
So you strategy should be creating an instance once on the heap, wrap it in a smart pointer for lifetime management and then just move around that smart pointer.
Besides all this, your code has some further errors. First of all your for
loop declaration is wrong. The condition for the loop end has to be before the increment. So right is
for (auto i = 0; i < 5; ++i)
Then you call myVector.clear();
in each loop iteration, which will basically remove everything you put in the vector before. Most likely not what you want 
TLDR, this could be your code:
// Declared as a member variable
std::vector<std::unique_ptr<A>> myVector;
// In your initialisation function
myVector.clear();
for (auto i = 0; i < 5; ++i)
{
auto myNewInstance = std::make_unique<A>();
mSteps.push_back (std::move (myNewInstance));
}