在C++中使用算法头文件出错

在C++中使用算法头文件出错,c++,include,bind,C++,Include,Bind,我制作了一个unix域服务器客户端。它工作完美,没有任何错误 然后我想使用来自算法头文件的random_shuffle函数。所以我只包含算法头文件。我没有做任何其他的改变。但现在在编译时,我得到了以下错误: game.cpp:102:85: error: no match for ‘operator!=’ in ‘std::bind(_Functor&&, _ArgTypes&& ...) [with _Functor = int&, _ArgTypes

我制作了一个unix域服务器客户端。它工作完美,没有任何错误

然后我想使用来自算法头文件的random_shuffle函数。所以我只包含算法头文件。我没有做任何其他的改变。但现在在编译时,我得到了以下错误:

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>&)
我没有做任何其他事情,我只是包括这个文件,那么为什么我会得到这个错误

如果有帮助,我将使用以下代码行编译它:

g++ -std=c++0x -I /usr/include/postgresql -lpq -fpermissive -c game.cpp

这是一个典型的名称冲突案例,因为不分青红皂白地使用using指令和在全局命名空间中导入的C API

您打算调用的绑定是用于中套接字的全局函数,但编译器更喜欢中提供的std::bind,您可能是用臭名昭著的using namespace std;导入该绑定的

要消除歧义,请告诉编译器使用全局绑定,而不是std中的绑定:

运算符前面没有任何名称空间意味着从全局名称空间中获取它,在全局名称空间中,除非原始头被包装在名称空间块中,否则将放置每个C API


无论如何,放弃使用名称空间std可能是更好的选择;指令,更倾向于在需要时使用std::或仅使用实际经常使用的内容进行导入。

除了包含,您还添加了一个使用名称空间std;或者其他什么。因此,编译器假定您需要std::bind,而实际上您需要使用::bind。另一种可能性是将系统函数封装在自己的小源文件中,这在任何情况下都不是一个坏主意,如果您希望将您的软件移植到具有不同调用的不同操作系统上运行,当然,然后使用一个合适的名称空间,该名称空间不会与其他组件发生冲突!或者只使用std中您想要的内容,而不是将整个名称空间拖入。ie:使用std::string;
g++ -std=c++0x -I /usr/include/postgresql -lpq -fpermissive -c game.cpp
if(::bind(socket_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0){