std::map
ofを値として保存しstd::shared_ptr<V>
ています。
1つの関数から、このマップへの参照を返したいのですが、std::shared_ptr<const V>
値型としてそれは可能ですか?
これが私が達成したいことです:
#include <map>
#include <memory>
struct A {
std::map<int, std::shared_ptr<int>> map;
const std::map<int, std::shared_ptr<const int>>& ret1() const {
return map;
}
};
しかし、このコードはコンパイルに失敗します:
error: invalid initialization of reference of type
'const std::map<int, std::shared_ptr<const int> >&'
from expression of type 'const std::map<int, std::shared_ptr<int> >'
ありがとう