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
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- 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::push_back() and vector::pop_back() in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- vector::crend() & vector::crbegin() with example
- vector :: cbegin() and vector :: cend() in C++ STL
- How to flatten a Vector of Vectors or 2D Vector in C++
- vector::empty() and vector::size() in C++ STL
- vector::begin() and vector::end() in C++ STL
- vector::at() and vector::swap() in C++ STL
- 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++
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Passing and Returning Objects in C++
- 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.