When class member is a vector object (not a reference).
We can simply assign in constructor.
1 2 3 4 5
We can also initialize using initialer list.
1 2 3 4 5
When class member is a vector a reference.
In C++, references must be initialized using initializer list.
1 2 3 4 5
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Passing by pointer Vs Passing by Reference in C++
- Passing vector to a function in C++
- vector::front() and vector::back() in C++ STL
- vector::empty() and vector::size() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- vector::at() and vector::swap() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::begin() and vector::end() in C++ STL
- vector :: cbegin() and vector :: cend() in C++ STL
- How to flatten a Vector of Vectors or 2D Vector in C++
- Parameter Passing Techniques in C/C++
- Passing Reference to a Pointer in C++
- How to delete an element from the Set by passing its value in C++
- Passing and Returning Objects in C++
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Copy constructor vs assignment operator in C++
- When is copy constructor called?
- When should we write our own copy constructor?
- Does C++ compiler create default constructor when we write our own?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.