Reputation: 127
I'm currently working on a matrix class and there is one part I've been stuck on.
If I wanted to initialize a class object with the contents of a vector for example
Matrix M = {1, 2, 3, 4, 5, 6}
Would I have to overload operator= or is it possible to create a constructor that can do that?
Upvotes: 0
Views: 22
Reputation: 93324
If by "vector" you mean std::vector
, then you can obviously create a constructor:
Matrix(const std::vector<int>&);
If you meant the {1, 2, 3, 4}
syntax, then you can create a constructor taking std::initializer_list
Matrix(const std::initializer_list<int>&);
Upvotes: 2