Say I have a class that looks like the following
template<std::size_t NumThings>
class Bar
{
public:
Bar(const int& v) : m_v(v) {}
std::array<int,NumThings> GetThings() const
{
std::array<int,NumThings> things;
for(std::size_t i = 0; i < NumThings; ++i)
things[i] = m_v;
return things;
}
protected:
const int& m_v;
};
template<std::size_t NumItems, std::size_t NumPieces>
class Foo
{
public:
Foo(const int& initialValue)
:
m_array(/* what do I do to pass initialValue to each item? */)
{}
protected:
std::array<Bar<NumPieces>,NumItems> m_array;
};
I'm unsure how to initialise the array of Bar
in the Foo
class by passing the parameter. I suppose I can't use {...}
sort of syntax because I don't know how many items yet, but I'm sure this there's some sort of meta-template programming trick I can use.
EDIT made default constructor of Bar
impossible.