Compile Error

foo.cc: In function ‘std::string addHighPrecisionFloats(const std::string&, const std::string&)’:
foo.cc:9:22: error: passing ‘const std::string’ {aka ‘const std::__cxx11::basic_string<char>’} as ‘this’ argument discards qualifiers [-fpermissive]
    9 |         num1 = "0" + num1;
      |                      ^~~~
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/string:54,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/bits/locale_classes.h:40,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/bits/ios_base.h:41,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/ios:44,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/ostream:40,
                 from iostream:41:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/basic_string.h:858:7: note:   in call to ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  858 |       operator=(basic_string&& __str)
      |       ^~~~~~~~
foo.cc:13:22: error: passing ‘const std::string’ {aka ‘const std::__cxx11::basic_string<char>’} as ‘this’ argument discards qualifiers [-fpermissive]
   13 |         num2 = "0" + num2;
      |                      ^~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/basic_string.h:858:7: note:   in call to ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  858 |       operator=(basic_string&& __str)
      |       ^~~~~~~~
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/string:51:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h: In instantiation of ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’:
/nix/gcc/include/c++/14-20241116/bits/stl_algo.h:1062:18:   required from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/nix/gcc/include/c++/14-20241116/bits/stl_algo.h:1089:21:   required from ‘void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.cc:17:17:   required from here
   17 |     std::reverse(num1.begin(), num1.end());
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h:185:11: error: no matching function for call to ‘swap(const char&, const char&)’
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/exception:166,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/ios:41:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/exception_ptr.h:230:5: note: candidate: ‘void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)’
  230 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/exception_ptr.h:230:25: note:   no known conversion for argument 1 from ‘const char’ to ‘std::__exception_ptr::exception_ptr&’
  230 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/bits/exception_ptr.h:41:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/move.h:214:5: note: candidate: ‘template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)’
  214 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/move.h:214:5: note:   template argument deduction/substitution failed:
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/bits/move.h:37:
/nix/gcc-14-20241116/include/c++/14-20241116/type_traits: In substitution of ‘template<bool _Cond, class _Tp> using std::__enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]’:
/nix/gcc-14-20241116/include/c++/14-20241116/type_traits:2323:11:   required by substitution of ‘template<class ... _Cond> using std::_Require = std::__enable_if_t<((bool)std::__and_<_Bn>::value)> [with _Cond = {std::__not_<std::__is_tuple_like<const char> >, std::is_move_constructible<const char>, std::is_move_assignable<const char>}]’
 2323 |     using _Require = __enable_if_t<__and_<_Cond...>::value>;
      |           ^~~~~~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/move.h:214:5:   required by substitution of ‘template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = const char]’
  214 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h:185:11:   required from ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/nix/gcc/include/c++/14-20241116/bits/stl_algo.h:1062:18:   required from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/nix/gcc/include/c++/14-20241116/bits/stl_algo.h:1089:21:   required from ‘void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.cc:17:17:   required from here
   17 |     std::reverse(num1.begin(), num1.end());
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/gcc-14-20241116/include/c++/14-20241116/type_traits:138:11: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
  138 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h: In instantiation of ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’:
/nix/gcc/include/c++/14-20241116/bits/stl_algo.h:1062:18:   required from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/nix/gcc/include/c++/14-20241116/bits/stl_algo.h:1089:21:   required from ‘void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const char*, __cxx11::basic_string<char> >]’
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.cc:17:17:   required from here
   17 |     std::reverse(num1.begin(), num1.end());
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/move.h:238:5: note: candidate: ‘template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])’
  238 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/move.h:238:5: note:   template argument deduction/substitution failed:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h:185:11: note:   mismatched types ‘_Tp [_Nm]’ and ‘const char’
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h:64:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_pair.h:1089:5: note: candidate: ‘template<class _T1, class _T2> void std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)’
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
/nix/gcc-14-20241116/include/c++/14-20241116/bits/stl_algobase.h:185:11: note:   mismatched types ‘std::pair<_T1, _T2>’ and ‘const char’
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~

信息

递交者
类型
递交
题目
P1693 求和 sum
语言
C++
递交时间
2025-04-07 21:03:00
评测时间
2025-04-07 21:03:00
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes