0

嗨,我有一个std::vector<T>::const_iterator作为参数的函数。

问题是:

如何将 T 类型的独立对象转换为迭代器,以便将其用作参数?

4

2 回答 2

3

“如何将 T 类型的独立对象转换为迭代器,以便将其用作参数?”

你不能。该独立对象需要存储在适当的容器中。只有容器提供迭代器的创建。

于 2015-04-29T17:40:35.353 回答
0

您不应该尝试将任意对象类型 T 转换为std::vector::const_iterator.

假设对象是 a std::vector<T>,您可以使用std::vector::cbeginorstd::vector::cend函数来获取 a std::vector::const_iterator

于 2015-04-29T17:42:01.853 回答