代码:

//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)
就可以了

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

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

    [C++]c++编译错误-- C2678 二进制"=": 没有找到接受"_Ty"类型的左操作数的运算符(或没有可接受的转换) 代码: //by 鸟哥 rever ...

  2. 二进制“==”: 没有找到接受“XX”类型的左操作数的运算符(或没有可接受的转换)

    项目场景: 自定义数据结构,进行内存数据的一些遍历等(QList等存储) 问题描述 因为出现==无法找到可接受的转换,那么你一定会像我一样,找==符号,一个项目里==符号那么多,要找到对应的对象==, ...

  3. ERROR:C2678 二进制“<”: 没有找到接受“const _Ty”类型的左操作数的运算符(或没有可接受的转换)

    [1]复现问题 为了更精确的分析,先用最简单的示例复现此错误场景,代码如下: #include <map> #include <string>struct Section {i ...

  4. C2678 二进制“<“:没有找到接受“ const_Ty“类型的左操作数的运算符

    C2678 二进制"<":没有找到接受" const_Ty"类型的左操作数的运算符 运行c++程序时遇到上述错误,点击VS中的错误后发现无法定位到错误所在 ...

  5. 错误 C2679 二进制“=”: 没有找到接受“const _Ty”类型的右操作数的运算符(或没有可接受的转换)的一种情况发生的错误

    错误 C2679 二进制"=": 没有找到接受"const _Ty"类型的右操作数的运算符(或没有可接受的转换 记录一下自己写代码出现的错误. 问题 写关于复数 ...

  6. C++ 没有找到接受const _Ty类型的左操作数的运算符

    在使用STL中的count(const )算法时报错没有找到接受const _Ty类型的左操作数的运算符, 原因是 使用自己创建的双向链表类没有重载左运算符== ,添加上重载运算即可. bool op ...

  7. QT中QSet容器报错: error: C2678: 二进制“==”: 没有找到接受“const Key类型的左操作数的运算符。

    该报错定位到qHash.h里.问题出在使用QSet存放了自定义的类. 解决方法:在类外重载(==)操作符和重写全局函数qHash. 具体如下: 头文件: //操作符重载(==) bool operat ...

  8. C2679 二进制 没有找到接受 std::string 类型的右操作数的运算符(或没有可接受的转换)

    在VS上打代码,结果出现了上面这个错误 很奇怪,以前在其他IDE上这么写都没有问题,不知道为什么在VS写就出现了这个错误,我一开始以为是我的代码的问题.可是怎么想都没有想通. 甚至,我自己在main函 ...

  9. (2110,5): warning MSB3245: 未能解析此引用。未能找到程序集“Windows”。请检查磁盘上是否存在该程序集。 如果您的代码需要此引用,则可能出现编译错误。

    最近打UE4的包的时候,总是失败.没办法只能各种搜索找答案解决,用了度娘.sougou.bing都没有找到理想的答案,最后没办法翻墙用google找答案,还好最后完美解决了. 下面是编译VS的erro ...

最新文章

  1. 基础 PHP 数据类型
  2. urlencode使用场景
  3. UDP(socket)接和数据案例封装成C++代码
  4. javascript --- repeat的用处
  5. Winform开发中另一种样式的OutLookBar工具条
  6. POJ 1502 MPI Maelstrom 最短路
  7. 利用 Charles Proxy 下载旧版本 iOS App
  8. MySQL binlog三种模式
  9. 【IE】IE对line-height 失效的的解决方案
  10. 配置管理系统和整体变更系统有什么区别与联系
  11. 白盒测试 语句覆盖、判定覆盖、条件覆盖、判定条件覆盖、条件组合覆盖、路径覆盖
  12. 消费心理学(02):沉没成本
  13. 傻瓜式脱壳保姆级教学
  14. html编写购物网站页面练习(一)
  15. 新研究评估Masimo Patient SafetyNet™对普通病房护理工作流程的效用
  16. 二进制数据图片(bit-data-map): 一种通过图片的形式传递数据信息的方式
  17. diy公益拍卖会 杨宗纬吴尊林俊杰s.h.e等拼人气
  18. [開發記錄] BBxM 系統建立
  19. PARALYSIS AS “SPIRITUAL LIBERATION” IN JOYCE’S DUBLINERS Iven Lucas Heister, B.A.【翻译】
  20. clear both

热门文章

  1. 【学习笔记】正确写作美国大学生数学建模竞赛论文(已获得国二、美O)
  2. Dubbo学习记录(十六)--服务调用【二】 - Invoker的调用、ProxyFactory、Protocol、Filter,Exchanger, Transporter扩展点
  3. 如何做一次完美的 ABTest?
  4. 亚马逊MWS开发--开始篇
  5. 分布式事务之 Atomikos
  6. 字节跳动数据库的过去、现状与未来
  7. 生活中的幽默!有趣的纸上立体插画艺术
  8. 【飞桨PaddleSpeech语音技术课程】— 语音翻译
  9. git精心_精心制作软件
  10. 2075:【21CSPJ普及组】插入排序(sort)(三种做法,层层优化)