在C++中使用算法头文件时出错
Error using algorithm header file in C++
我做了一个Unix域服务器客户端。它完美运行,没有任何错误。
然后我想使用algorithm
头文件中的random_shuffle()
函数。所以我只包含algorithm
头文件。我没有进行任何其他更改。但是现在在编译时,我收到以下错误:
game.cpp:102:85: error: no match for ‘operator!=’ in ‘std::bind(_Functor&&, _ArgTypes&& ...) [with _Functor = int&, _ArgTypes = {sockaddr*, long unsigned int}, typename std::_Bind_helper<_Functor, _ArgTypes>::type = std::_Bind<int(sockaddr*, long unsigned int)>]((* &((sockaddr*)(& address))), (* &110ul)) != 0’
game.cpp:102:85: note: candidates are:
/usr/include/c++/4.6/bits/stl_pair.h:214:5: note: template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.6/bits/stl_iterator.h:297:5: note: template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/stl_iterator.h:347:5: note: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/stl_iterator.h:1037:5: note: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/stl_iterator.h:1043:5: note: template<class _Iterator> bool std::operator!=(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/postypes.h:223:5: note: template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/usr/include/c++/4.6/bits/allocator.h:132:5: note: template<class _T1, class _T2> bool std::operator!=(const std::allocator<_T1>&, const std::allocator<_T2>&)
/usr/include/c++/4.6/bits/allocator.h:137:5: note: template<class _Tp> bool std::operator!=(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
/usr/include/c++/4.6/bits/basic_string.h:2473:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2485:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2497:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.6/bits/streambuf_iterator.h:200:5: note: template<class _CharT, class _Traits> bool std::operator!=(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
/usr/include/c++/4.6/bits/stl_vector.h:1297:5: note: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
/usr/include/c++/4.6/bits/random.h:338:5: note: template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> bool std::operator!=(const std::linear_congruential_engine<_UIntType, __a, __c, __m>&, const std::linear_congruential_engine<_UIntType, __a, __c, __m>&)
/usr/include/c++/4.6/bits/random.h:568:5: note: template<class _UIntType, long unsigned int __w, long unsigned int __n, long unsigned int __m, long unsigned int __r, _UIntType __a, long unsigned int __u, _UIntType __d, long unsigned int __s, _UIntType __b, long unsigned int __t, _UIntType __c, long unsigned int __l, _UIntType __f> bool std::operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>&, const std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>&)
/usr/include/c++/4.6/bits/random.h:765:5: note: template<class _UIntType, long unsigned int __w, long unsigned int __s, long unsigned int __r> bool std::operator!=(const std::subtract_with_carry_engine<_UIntType, __w, __s, __r>&, const std::subtract_with_carry_engine<_UIntType, __w, __s, __r>&)
/usr/include/c++/4.6/bits/random.h:987:5: note: template<class _RandomNumberEngine, long unsigned int __p, long unsigned int __r> bool std::operator!=(const std::discard_block_engine<_RandomNumberEngine, __p, __r>&, const std::discard_block_engine<_RandomNumberEngine, __p, __r>&)
/usr/include/c++/4.6/bits/random.h:1183:5: note: template<class _RandomNumberEngine, long unsigned int __w, class _UIntType> bool std::operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w, _UIntType>&, const std::independent_bits_engine<_RandomNumberEngine, __w, _UIntType>&)
/usr/include/c++/4.6/bits/random.h:1433:5: note: template<class _RandomNumberEngine, long unsigned int __k> bool std::operator!=(const std::shuffle_order_engine<_RandomNumberEngine, __k>&, const std::shuffle_order_engine<_RandomNumberEngine, __k>&)
/usr/include/c++/4.6/bits/random.h:1735:5: note: template<class _IntType> bool std::operator!=(const std::uniform_int_distribution<_IntType>&, const std::uniform_int_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:1916:5: note: template<class _IntType> bool std::operator!=(const std::uniform_real_distribution<_IntType>&, const std::uniform_real_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:2136:5: note: template<class _RealType> bool std::operator!=(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:2312:5: note: template<class _RealType> bool std::operator!=(const std::lognormal_distribution<_RealType>&, const std::lognormal_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:2504:6: note: template<class _RealType> bool std::operator!=(const std::gamma_distribution<_RealType>&, const std::gamma_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:2669:5: note: template<class _RealType> bool std::operator!=(const std::chi_squared_distribution<_RealType>&, const std::chi_squared_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:2808:5: note: template<class _RealType> bool std::operator!=(const std::cauchy_distribution<_RealType>&, const std::cauchy_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:3024:5: note: template<class _RealType> bool std::operator!=(const std::fisher_f_distribution<_RealType>&, const std::fisher_f_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:3198:5: note: template<class _RealType> bool std::operator!=(const std::student_t_distribution<_RealType>&, const std::student_t_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:3346:3: note: bool std::operator!=(const std::bernoulli_distribution&, const std::bernoulli_distribution&)
/usr/include/c++/4.6/bits/random.h:3346:3: note: no known conversion for argument 1 from ‘std::_Bind_helper<int&, sockaddr*, long unsigned int>::type {aka std::_Bind<int(sockaddr*, long unsigned int)>}’ to ‘const std::bernoulli_distribution&’
/usr/include/c++/4.6/bits/random.h:3583:5: note: template<class _IntType> bool std::operator!=(const std::binomial_distribution<_IntType>&, const std::binomial_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:3725:5: note: template<class _IntType> bool std::operator!=(const std::geometric_distribution<_IntType>&, const std::geometric_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:3931:5: note: template<class _IntType> bool std::operator!=(const std::negative_binomial_distribution<_IntType>&, const std::negative_binomial_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:4119:5: note: template<class _IntType> bool std::operator!=(const std::poisson_distribution<_IntType>&, const std::poisson_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:4269:5: note: template<class _RealType> bool std::operator!=(const std::exponential_distribution<_RealType>&, const std::exponential_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:4444:5: note: template<class _RealType> bool std::operator!=(const std::weibull_distribution<_RealType>&, const std::weibull_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:4619:5: note: template<class _RealType> bool std::operator!=(const std::extreme_value_distribution<_RealType>&, const std::extreme_value_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:4851:5: note: template<class _IntType> bool std::operator!=(const std::discrete_distribution<_IntType>&, const std::discrete_distribution<_IntType>&)
/usr/include/c++/4.6/bits/random.h:5090:5: note: template<class _RealType> bool std::operator!=(const std::piecewise_constant_distribution<_RealType>&, const std::piecewise_constant_distribution<_RealType>&)
/usr/include/c++/4.6/bits/random.h:5332:5: note: template<class _RealType> bool std::operator!=(const std::piecewise_linear_distribution<_RealType>&, const std::piecewise_linear_distribution<_RealType>&)
/usr/include/c++/4.6/tuple:597:5: note: template<class ... _TElements, class ... _UElements> bool std::operator!=(const std::tuple<_TElements ...>&, const std::tuple<_Elements ...>&)
/usr/include/c++/4.6/functional:2245:5: note: template<class _Res, class ... _Args> bool std::operator!=(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)
/usr/include/c++/4.6/functional:2251:5: note: template<class _Res, class ... _Args> bool std::operator!=(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
/usr/include/c++/4.6/bits/unordered_map.h:210:5: note: template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, bool __cache_hash_code> bool std::operator!=(const std::__unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc, __cache_hash_code>&, const std::__unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc, __cache_hash_code>&)
/usr/include/c++/4.6/bits/unordered_map.h:228:5: note: template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, bool __cache_hash_code> bool std::operator!=(const std::__unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc, __cache_hash_code>&, const std::__unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc, __cache_hash_code>&)
/usr/include/c++/4.6/bits/unordered_map.h:390:5: note: template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> bool std::operator!=(const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&)
/usr/include/c++/4.6/bits/unordered_map.h:402:5: note: template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> bool std::operator!=(const std::unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&, const std::unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&)
在line 102
我正在使用以前正常工作的bind
功能。这是line 102
:
if(bind(socket_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0){
我没有做任何其他事情,我只是包含了这个文件,那么为什么我会收到此错误?
如果它有帮助,我将使用以下代码行编译它:
g++ -std=c++0x -I /usr/include/postgresql -lpq -fpermissive -c game.cpp
这是由于不分青红皂白地使用using
指令和在全局命名空间中导入的 C API 而导致名称冲突的典型案例。
您打算调用的bind
是用于套接字的全局函数(来自<sys/sockets.h>
),但编译器更喜欢<algorithm>
中提供的std::bind
,您可能将其与臭名昭著的using namespace std;
一起导入。
要消除歧义,请告诉编译器使用全局绑定而不是std
中的全局绑定:
if(::bind(socket_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0){
(前面没有任何命名空间的::
运算符意味着"从全局命名空间中获取这个",除非原始标头包装在namespace
块中,否则每个 C API 都将被放置)
无论如何,放弃using namespace std;
指令可能是一个更好的选择,在需要时更喜欢使用std::
,或者只导入using
你实际经常使用的东西。
相关文章:
- 读取文件的最后一行并输入到链接列表时出错
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 在 C/C++ 中打开驻留在 "/sys/" 下的文件时出错
- 在头文件中定义变量不会出错
- 如何在多写入器情况下对文件支持的共享内存中的大页面出错
- JNI,使用两个 .so 文件时出错,其中一个文件需要另一个文件
- 生成文件中隐式规则中的 -c 标志出错
- 编译时出错 - 链接.cpp和头文件
- 从人员矢量插入和读取文件时出错
- LNK2019 在文件中调用静态成员的方法时出错.cpp
- ./main:加载共享库时出错:libopencv_highgui.so.4.0:无法打开共享对象文件:没有这样的文件或
- 猫鼬 - 包含标准C++库文件时出错
- 在f2c.h文件中定义min()max()宏时出错
- ASIOSDK;从hostsample.cpp生成mex文件时出错
- 使用emscripten将c++文件转换为wasm时出错
- 编译后可执行文件出错
- 头文件C++出错
- ftell 非常大的文件出错
- 从磁盘读取映像文件出错