jeudi 31 octobre 2019

How would I get this functionality in my matrix class? [duplicate]

This question already has an answer here:

#include <iostream>
#include <array>

template<typename T, std::size_t R, std::size_t C>
class matrix
{
   std::array<T, R * C> m_data;
};

int main() 
{
   matrix<float, 2, 2> a = { 1,2,3,4 }; // COMPILER ERROR!
}

Clang reports that there is no matching constructor!

I have tried writing a constructor of the form

matrix(std::array<T,R*C> a);

and tried experimenting with && as I think the right-hand side of the expression in question is temporary. Which leads me to some confusion. As we would expect that it would be created then assigned(!) to the value of a.

Aucun commentaire:

Enregistrer un commentaire