I want to make a constructor with array and array size so I can call the object using this: Multime m1 = Multime({1, 2, 3}, 3);
Or should I use std::vector instead?
class Multime
{
private:
int elemente[100];
int size;
public:
Multime(){}
Multime(int el[50], int s){
this -> size = s;
for(int i = 0; i < this -> size; i++)
this -> elemente[i] = el[i];
}
};
int main()
{
Multime m1 = Multime({1, 2, 3}, 3);
return 0;
}
And i'm getting No matching constructor for initialization of 'Multime'
std::vectororstd::initializer_listas argument?{1, 2, 3}evaluates to an array of integers?std::initializer_listparameter and avoid the need to pass an explicit array size parameter, and this will work; but this is a fairly advanced topic, see your C++ book for the details.int el[](size is irrelevant) will be treated asint* el, in other words the function expects a pointer as argument. Your compiler should have mentioned it in the complete error message (though it might have been a little indirect).