Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我有一个std::vector<T>::const_iterator作为参数的函数。
std::vector<T>::const_iterator
问题是:
如何将 T 类型的独立对象转换为迭代器,以便将其用作参数?
“如何将 T 类型的独立对象转换为迭代器,以便将其用作参数?”
你不能。该独立对象需要存储在适当的容器中。只有容器提供迭代器的创建。
您不应该尝试将任意对象类型 T 转换为std::vector::const_iterator.
std::vector::const_iterator
假设对象是 a std::vector<T>,您可以使用std::vector::cbeginorstd::vector::cend函数来获取 a std::vector::const_iterator。
std::vector<T>
std::vector::cbegin
std::vector::cend