Why can't I compile unique_ptr <pair <int, int & >>
I am trying to create a pair where one of the two elements of the pair is a link. If I try to create a unique ptr for this pair, I get an error from a utility that cannot convert int to int &.
I realize that I didn't have a default built pair, but my intention (by putting it in the ptr) was only new when I have something for that int to reference too.
unique_ptr<pair<int, int&>> uptr; // Full error posted below
shared_ptr<pair<int, int&>> sptr; // Compiles fine
Full error:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(145) : error C2440: 'initializing' : cannot convert from 'int' to 'int &'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(142) : while compiling class template member function 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base(int &&,int &&)'
with
[
_Ty1=int,
_Ty2=int &
]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(174) : see reference to class template instantiation 'std::_Pair_base<_Ty1,_Ty2>' being compiled
with
[
_Ty1=int,
_Ty2=int &
]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\memory(2161) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled
with
[
_Ty1=int,
_Ty2=int &
]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\memory(2195) : see reference to class template instantiation 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>' being compiled
with
[
_Ty=std::pair<int,int &>,
_Dx=std::default_delete<std::pair<int,int &>>,
_Empty_deleter=true
]
myClass.h(99) : see reference to class template instantiation 'std::unique_ptr<_Ty>' being compiled
with
[
_Ty=std::pair<int,int &>
]
I would think this would compile and not be able to figure out why something is being initialized on that line, or where it is not a ref ref.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: