You didn't provide a constructor for your class, so the compiler generates a default one, which default-initialises all members of the class. And default-initialising a built-in type means it's not initialised at all, so any use of its value is undefined. In other words, scalars
is not initialised to anything.
You can fix it like this:
template<std::size_t N>
class dummy
{
public:
float& operator[](const std::size_t ind) { return scalars[ind]; }
dummy() : scalars()
{}
private:
float scalars[N*N];
};
using dummy2 = dummy<2>;
This makes scalars
value-initialised instead of default-initialised, and value-initialising a float
sets it to 0.f
, so everything will work.