|
|
1>chapter19ex3.cpp(98,9): error : call to constructor of 'Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>' is ambiguous 1> return Pair<T1, T2>(std::forward<T1>(x), std::forward<T2>(y)); 1> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1>chapter19ex3.cpp(51,34) : note: in instantiation of member function 'Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::make_pair' requested here 1> my_table.push_back(my_table[i].make_pair(strs[i], i * i + 1)); 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\xmemory0(856,4): error : call to implicitly-deleted copy constructor of 'Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>' 1> _Objty(_STD forward<_Types>(_Args)...); 1> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1>In file included from chapter19ex3.cpp:14: 1>In file included from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\vector:6: 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\xmemory(140,3): error : no matching function for call to 'construct' 1> allocator_traits<_Alloc>::construct(_Al, _Unfancy(_Dest), _STD move(*_First)); 1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\xmemory(171,3) : note: in instantiation of function template specialization 'std::_Uninitialized_move_al_unchecked<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> *, Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> *, std::allocator<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >' requested here 1> _Uninitialized_move_al_unchecked(_UFirst, _ULast, _UDest, _Al, 1> ^ 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\vector(1924,3) : note: in instantiation of function template specialization 'std::_Uninitialized_move<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> *, Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> *, std::allocator<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >' requested here 1> _Uninitialized_move(_First, _Last, _Dest, this->_Getal()); 1> ^ 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\vector(1934,3) : note: in instantiation of member function 'std::vector<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::allocator<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::_Umove_if_noexcept1' requested here 1> _Umove_if_noexcept1(_First, _Last, _Dest, 1> ^ 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\vector(960,4) : note: in instantiation of member function 'std::vector<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::allocator<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::_Umove_if_noexcept' requested here 1> _Umove_if_noexcept(this->_Myfirst(), this->_Mylast(), _Newvec); 1> ^ 1>chapter19ex3.cpp(51,12) : note: in instantiation of member function 'std::vector<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::allocator<Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::push_back' requested here 1> my_table.push_back(my_table[i].make_pair(strs[i], i * i + 1)); 1> ^ 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\xmemory0(853,15) : note: candidate template ignored: substitution failure [with _Objty = Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, _Types = <Pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>>] 1> static void construct(_Alloc&, _Objty * const _Ptr, _Types&&... _Args) 1> ^ |
Pair
object.my_table.emplace_back(strs[i], i * i + 1);
instead of my_table.push_back(my_table[i].make_pair(strs[i], i * i + 1));
. Your code will crash if you leave it as it is.var a 1 var b 2 var c 5 var x 10 var y 17 Press any key to continue . . . |
default
if you do not want to write every constructor and a default implementation will be sufficient.Pair
rvalue reference, since you've already made similar constructors.make_pair
and Pair(T1 first, T2 second)
both parameters can be a const reference, like (const T1 &first, const T2 &second)
.
my_table.push_back(my_table[i].make_pair(strs[i], i * i + 1));
you try to access an empty vector.
|
|
var a 1 var b 2 var c 5 var x 10 var y 17 |
|
|
|
|
|
|
|
|