Yes a raw array can be more efficient, however IMO the fact that you must always pass the size into a function along with the array erases most if not all of those efficiencies. When dealing with a std::array most of the effiencies are also lost if you try to write reusable code, code that can be used with any array size.But if you do have a compile time constant size, then an array is more efficient.
IMO std::vector should be the default vector, only use something else if there is a good reason. For example a list may be a better choice if you don't need random access and you will be inserting and removing elements to to other than the back of the container.However, vector is a good default container.
Yes, you can use range based loops with raw arrays, as long as the array definition is in the same scope (it hasn't decayed to a pointer). You can't use ranged based loops with a raw array that is passed into a function for example.Can you really use range-based syntax with a raw array? I thought it was just syntactic sugar for the `begin` and `end` methods.
Because you can pass a std::vector to a function no matter the size of the vector. With a std::array you need some "magic" to be able to write a function that can take a std::array of any size.I don't also see why a vector would be better when writing reusable code.
It is only really an advantage when the array is small enough for the stack. I feel that because a std::vector places the elements on the heap is an advantage, not a disadvantage.Plus, std::array is on the stack and that is an advantage.
Why not something more like:Code:do{ dog_list.push_back(d); for (it = dog_list.begin(); ; ++it){ (*it).setDog(); } cout<<endl; }while ((*it).nameDog() != " ");
Code:... while (d.setDog()) { dog_list.push_back(d); } cout<<endl; for (auto& it : dog_list){ it.showDog(); cout<<endl; ... bool Dog::setDog(){ cout << "Enter dog's name: "; cin >> m_name; cout <<"Enter dog's age: "; cin >> m_age; return m_name.empty(); }
By the way Dog::showDog() should also be const qualified.
Jim