【C++】c++编译错误-- C2678 二进制“=”: 没有找到接受“_Ty”类型的左操作数的运算符(或没有可接受的转换)

11 篇文章 0 订阅

【C++】c++编译错误-- C2678 二进制“=”: 没有找到接受“_Ty”类型的左操作数的运算符(或没有可接受的转换)

代码:

//by 鸟哥 reverse引起的编译错误
//有疑问请留言或加群 1032082534
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
class Point3d{
    double x,y,z;
    public:
    Point3d(double x,double y,double z):x(x),y(y),z(z){}
    bool operator == (const Point3d &p) {
        return (this->x == p.x)&&(this->y == p.y)&&(this->z == p.z);
    }
};
class Points:public vector<Point3d>{
    
};

void myreverse(const Points&  ps){
    std::reverse(ps.begin(),ps.end());
}

int main(){
    
    //vector<Point3d> p{{0,0,0},{1,2,3},{1.1,2.1,3.1},{10,11,11}};
    Points p;//{Point3d{0,0,0},Point3d{1,2,3},Point3d{1.1,2.1,3.1},Point3d{10,11,11}};
    p.push_back(Point3d{1,1,2});p.push_back(Point3d{1,10,2});
    myreverse(p);
}

gcc 9.2下的编译输出:

Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-9.2.0/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-9.2.0/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: …/gcc-9.2.0/configure --prefix=/opt/wandbox/gcc-9.2.0 --enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl --enable-checking=release --disable-nls LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-9.2.0/lib,-rpath,/opt/wandbox/gcc-9.2.0/lib64,-rpath,/opt/wandbox/gcc-9.2.0/lib32 --enable-lto
Thread model: posix
gcc version 9.2.0 (GCC)
COLLECT_GCC_OPTIONS=’-o’ ‘prog.exe’ ‘-I’ ‘/opt/wandbox/boost-sml/include’ ‘-I’ ‘/opt/wandbox/boost-di/include’ ‘-I’ ‘/opt/wandbox/range-v3/include’ ‘-I’ ‘/opt/wandbox/nlohmann-json/include’ ‘-I’ ‘/opt/wandbox/cmcstl2/include’ ‘-I’ ‘/opt/wandbox/te/include’ ‘-I’ ‘/opt/wandbox/boost-1.72.0/gcc-9.2.0/include’ ‘-L/opt/wandbox/boost-1.72.0/gcc-9.2.0/lib’ ‘-std=c++17’ ‘-Wall’ ‘-Wextra’ ‘-v’ ‘-shared-libgcc’ ‘-mtune=generic’ ‘-march=x86-64’
/opt/wandbox/gcc-9.2.0/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/cc1plus -quiet -v -I /opt/wandbox/boost-sml/include -I /opt/wandbox/boost-di/include -I /opt/wandbox/range-v3/include -I /opt/wandbox/nlohmann-json/include -I /opt/wandbox/cmcstl2/include -I /opt/wandbox/te/include -I /opt/wandbox/boost-1.72.0/gcc-9.2.0/include -imultiarch x86_64-linux-gnu -D_GNU_SOURCE prog.cc -quiet -dumpbase prog.cc -mtune=generic -march=x86-64 -auxbase prog -Wall -Wextra -std=c++17 -version -o /tmp/ccxVwEsg.s
GNU C++17 (GCC) version 9.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 9.2.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory “/usr/local/include/x86_64-linux-gnu”
ignoring nonexistent directory “/usr/local/include”
ignoring nonexistent directory “/opt/wandbox/gcc-9.2.0/lib/gcc/x86_64-pc-linux-gnu/9.2.0/…/…/…/…/x86_64-pc-linux-gnu/include”
#include “…” search starts here:
#include <…> search starts here:
/opt/wandbox/boost-sml/include
/opt/wandbox/boost-di/include
/opt/wandbox/range-v3/include
/opt/wandbox/nlohmann-json/include
/opt/wandbox/cmcstl2/include
/opt/wandbox/te/include
/opt/wandbox/boost-1.72.0/gcc-9.2.0/include
/opt/wandbox/gcc-9.2.0/lib/gcc/x86_64-pc-linux-gnu/9.2.0/…/…/…/…/include/c++/9.2.0
/opt/wandbox/gcc-9.2.0/lib/gcc/x86_64-pc-linux-gnu/9.2.0/…/…/…/…/include/c++/9.2.0/x86_64-pc-linux-gnu
/opt/wandbox/gcc-9.2.0/lib/gcc/x86_64-pc-linux-gnu/9.2.0/…/…/…/…/include/c++/9.2.0/backward
/opt/wandbox/gcc-9.2.0/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include
/opt/wandbox/gcc-9.2.0/include
/opt/wandbox/gcc-9.2.0/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++17 (GCC) version 9.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 9.2.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 655e7cdff85c114835c364187fb656a8
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/char_traits.h:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h: In instantiation of ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algo.h:1160:18: required from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algo.h:1186:21: required from ‘void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’
prog.cc:20:37: required from here
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:151:11: error: no matching function for call to ‘swap(const Point3d&, const Point3d&)’
151 | swap(__a, __b);
| ^~~~~~~~
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/nested_exception.h:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/exception:144,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/move.h:182:5: note: candidate: ‘template typename std::enable_if<std::_and<std::_not<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)’
182 | swap(_Tp& __a, _Tp& __b)
| ^~~~
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/move.h:182:5: note: template argument deduction/substitution failed:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/move.h: In substitution of ‘template typename std::enable_if<std::_and<std::_not<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&) [with _Tp = const Point3d]’:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:151:11: required from 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const Point3d, std::vector >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const Point3d, std::vector >]’
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algo.h:1160:18: required from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algo.h:1186:21: required from ‘void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’
prog.cc:20:37: required from here
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/move.h:182:5: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h: In instantiation of ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algo.h:1160:18: required from ‘void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algo.h:1186:21: required from ‘void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const Point3d*, std::vector >]’
prog.cc:20:37: required from here
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/move.h:205:5: note: candidate: ‘template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])’
205 | swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
| ^~~~
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/move.h:205:5: note: template argument deduction/substitution failed:
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/char_traits.h:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:151:11: note: mismatched types ‘_Tp [_Nm]’ and ‘const Point3d’
151 | swap(*__a, __b);
| ^~~~~~~~
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:64,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/char_traits.h:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_pair.h:495:5: note: candidate: ‘template<class _T1, class _T2> typename std::enable_if<std::_and<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)’
495 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
| ^~~~
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_pair.h:495:5: note: template argument deduction/substitution failed:
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/char_traits.h:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:151:11: note: types ‘std::pair<_T1, _T2>’ and ‘const Point3d’ have incompatible cv-qualifiers
151 | swap(__a, __b);
| ^~~~~~~~
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:64,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/char_traits.h:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_pair.h:503:5: note: candidate: ‘template<class _T1, class _T2> typename std::enable_if<(! std::_and<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)’
503 | swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
| ^~~~
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_pair.h:503:5: note: template argument deduction/substitution failed:
In file included from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/char_traits.h:39,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ios:40,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/ostream:38,
from /opt/wandbox/gcc-9.2.0/include/c++/9.2.0/iostream:39,
from prog.cc:3:
/opt/wandbox/gcc-9.2.0/include/c++/9.2.0/bits/stl_algobase.h:151:11: note: types ‘std::pair<_T1, _T2>’ and ‘const Point3d’ have incompatible cv-qualifiers
151 | swap(__a, *__b);
| ^~~~~~~~

如果在vs2019下编译,错误类似于这样:

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2678 二进制“=”: 没有找到接受“_Ty”类型的左操作数的运算符(或没有可接受的转换) MyNestCore D:\Program Files (x86)\vs2019\VC\Tools\MSVC\14.24.28314\include\utility 62

原因是 函数的形参里用了const
void myreverse(const Points& ps)
改成
void myreverse(Points& ps)
就可以了

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值