Я пытаюсь использовать unique_ptr из C ++ x0, выполнив
#include <memory>
и выполнив команду -std = c ++ 0x, однако она выдает много ошибок, так какпример.
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/bits/unique_ptr.h:214: error: deleted function ‘std::unique_ptr<_Tp, _Tp_Deleter>::unique_ptr(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = Descriptor, _Tp_Deleter = std::default_delete<Descriptor>]’
ОБНОВЛЕНИЕ **** Это то, что я пытаюсь сделать, я удалил typedefs, чтобы вы могли четко видеть типы
static std::unique_ptr<SomeType> GetSomeType()
{
std::unique_ptr<SomeType> st("Data","Data2",false);
std::unique_ptr<OtherType> ot("uniportantconstructor data");
st->Add(ot);
return st;
}
//Public method of SomeType
void Add(std::unique_ptr<OtherType> ot)
{
//otmap is std::map<std::string,std::unique_ptr<OtherType> >
//mappair is std::Pair<std::string,std::unique_ptr<OtherType> >
otMap.Insert(mappair(ot->name(),ot));
}
ОБНОВЛЕНИЕ:
Если в моем классе SomeType есть метод, который возвращает элемент с карты (используя ключ), скажем
std::unique_ptr<OtherType> get_othertype(std::string name)
{
return otMap.find(name);
}
, который гарантирует, что вызывающая сторона получит указатель на тот, что на карте, а некопия