Search code examples
c++vectoriteratorconst-iterator

Cast object into vector's const_iterator


Hi I have a function which takes std::vector<T>::const_iterator as parameter.

Question is:

How can I cast standalone object of type T, into iterator, so I can use it as an argument?


Solution

  • "How can I cast standalone object of type T, into iterator, so I can use it as an argument?"

    You cannot. That standalone object needs to be stored in an appropriate container. Only containers provide creation of iterators.