0
나는 값으로 std::shared_ptr<V>
의 std::map
을 저장할 것입니다.지도 <K, shared_ptr >을 (를) 매핑하려면 <K, shared_ptr <V>>을 전송 하시겠습니까?
하나의 함수에서이 맵에 대한 참조를 반환하지만 값 유형으로 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> >'
감사