我想获得一个迭代器到我的向量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();
}
};
工作!但我有另一个问题。我将typedef行改为:typedef std :: string Entry;它编译。为什么我需要shared_ptr版本的代码的类型名称? [&不是字符串版本] – RandomClown 2014-09-06 21:08:34
@RandomClown:已更新 – 2014-09-06 21:18:00