I assume this is an exercise you're doing? If you actually needed to do this, you'd just use a vector. I see your fillArray function takes in a vector, but does nothing with it. What's that about?
1 2 3 4 5 6 7 8 9 10
void fillArray(vector<int> numbers)
{
for (int index = 0; index < m_length; ++index)
{
int value;
cout << "Enter value: ";
cin >> value;
m_array[index] = value;
}
}
Sorry, yes it's fillArray function that I want to know if it can be written better. Well, the idea was that I will dynamically allocate memory with std::vector...with length and it's values being known from input. That "cout << "enter value:" is what I was looking for and I am just readng about overloading [] so thanks!
May I ask you some more details? Just to avoid writing code you don’t need.
What are you trying to achieve? If you want to do your version of std::vector, well, I think you shouldn’t use std::vector at all :-) std::vectors already do what you seem to be asking for, so, if you can use them, just use them.
If that’s not what you’re trying to achieve, could you please clarify what your class should do?
And, please, could you answer Repeater’s question and tell us if this is a teacher’s assignment?
Yes it was assigment, but I wanted to include dynamicaly allocated array, instead of just plain string etc. . But now I did some self study and found std::list_initializer among other things, so thanks!