This problem is also on stackoverflow: <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1391001" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1391001</a>.<p>It solved it by wrapping with a superclass that you downcast from. You won&#x27;t be able to work with them by value due to object slicing but you can still have a vector of pointers:<p><pre><code>    vector&lt;Panda_without_bamboo*&gt; pandas;
</code></pre>
I am not sure how to do the downcasting though. Assuming the classes look like this:<p><pre><code>    public Panda_without_bamboo
    {
       int bambooCount;
    }

    template&lt;std::size_t N&gt;
    class Panda_with_bamboo : public Panda_without_bamboo
    {
       int a;
       int b;
       Bamboo bamboo[N];
    }
</code></pre>
You can&#x27;t really do:<p><pre><code>    static_cast&lt;Panda&lt;pandas[0].bambooCount&gt;*&gt;(pandas[0])


</code></pre>
So it does seem like using flexible array members (first answer in that stackoverflow and the topic discussed in this submission) is a cleaner solution if you need contiguous allocation: <a href="http:&#x2F;&#x2F;www.codeatcpp.com&#x2F;2007&#x2F;10&#x2F;dynamic-array-template.html" rel="nofollow">http:&#x2F;&#x2F;www.codeatcpp.com&#x2F;2007&#x2F;10&#x2F;dynamic-array-template.html</a>