2012-12-28 1 views
0

유닉스 도메인 server-client를 만들었습니다. 오류없이 완벽하게 작동합니다.C++에서 알고리즘 헤더 파일을 사용하는 중 오류가 발생했습니다

그런 다음 헤더 파일의 random_shuffle() 기능을 사용하고 싶습니다. 따라서 헤더 파일은 algorithm입니다. 나는 다른 어떤 변화도하지 않았다. 하지만 지금 컴파일에 나는 다음과 같은 오류가 점점 오전 : 내가 제대로 작동은 전에 있던 bind 기능을 사용하고 line 102

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이다 : 나는 아무것도하지 않은

if(bind(socket_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0){ 

방금이 파일을 포함하고 왜이 오류가 발생 했습니까?

그리고 그것은 내가 다음 코드 줄을 사용하여 컴파일하고 도움이 될 수있는 경우 :

인해 글로벌 네임 스페이스에 수입 무차별 using 지시어의 사용과 C API에 이름 충돌의 고전적인 사례이다
g++ -std=c++0x -I /usr/include/postgresql -lpq -fpermissive -c game.cpp 
+2

'#include '외에도'using namespace std;'(또는 그 계정에 무엇인가)를 추가했습니다. 결과적으로 컴파일러는 당신이 정말로':: bind'를 사용하기를 원할 때'std :: bind'를 원한다고 가정합니다. – IInspectable

답변

7

.

bind 당신이 (<sys/sockets.h>에서) 소켓에 사용되는 전역 함수이었다 호출하도록하지만, 컴파일러는 아마 당신은 악명 높은 using namespace std;과 수입 <algorithm>에서 제공하는 std::bind을 선호했다.

는 명확 대신 std에서 하나의 글로벌 바인드를 사용하도록 컴파일러에게 :

if(::bind(socket_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0){ 

(모든 네임 스페이스가 선행되지 :: 연산자는 "글로벌 네임 스페이스에서이 잡아"의미 원래 헤더가 namespace 블록으로 감싸지 않는 한 모든 C API가 적용됩니다.

using namespace std; 지시어를 삭제하는 것이 더 좋을 수도 있습니다.의 사용을 선호합니다.또는 필요할 때 실제로 using과 함께 가져올 수 있습니다.

+1

또 다른 가능성은 자체 소규모 소스 파일에 시스템 기능을 래핑하는 것입니다 (다른 호출이있는 다른 OS에서 실행되도록 소프트웨어를 포팅해야한다면 나쁜 생각이 아닙니다). 다른 구성 요소와 충돌하지 않는 적합한 네임 스페이스! –

+1

또는 네임 스페이스 전체를 드래그하는 대신 std에서 원하는 것을 사용하십시오. 즉 : std :: string; –

관련 문제