【发布时间】:2014-10-31 12:27:50
【问题描述】:
我正在尝试获取 shared_ptr 向量的迭代器。它给了我 2 个编译错误:
syntax error : missing ';' before identifier 'begin'
missing type specifier - int assumed. Note: C++ does not support default-int
在代码中,如果我将向量的条目类型替换为字符串或其他基本类型,它就会编译。 [当然这不是我想要的]。怎么回事?
#include <vector>
#include <unordered_map>
#include <memory>
template<class _Kty, class _Ty> class MyClass {
public:
typedef std::shared_ptr<std::pair<_Kty, _Ty>> Entry;
// Vector containing pairs of the key & value
std::vector<Entry> container;
// Beginning iterator to the vector part
std::vector<Entry>::iterator begin() noexcept {
return containervector.begin();
}
};
【问题讨论】:
标签: templates c++11 vector iterator shared-ptr