2012-02-01 3 views
0

나는 이러한 방법으로, 표준 : : 찾기 기능을 오버로드 시도 :과부하 : 찾기 기능

include <list> 
include <string> 
include "Marker.h" 

namespace Test { 



    class MarkerContainer { 

    private: 
     std::list<Marker*> list; 
     double end_t; 
     inline bool exists(std::list<Marker*> *input_list, Marker* check); 
    public: 

     MarkerContainer(); 
     MarkerContainer(double end_time); 
     bool addMarker(Marker* input); 
     double computeBeatTime(double sample_t); 
     double computeSampleTime(double beat_t);  
     void printAll(); 

    }; 

    } 


    std::list<Ableton::Marker*>::iterator std::find(std::list<Ableton::Marker*>::iterator first, std::list<Ableton::Marker*>::iterator last, Ableton::Marker* value){ 
      for (;first!=last; first++) if (**first==*value) break; 
      return first; 

     } 

하지만이 컴파일러 오류 잡기 : 나는 어떤을했다 희망

Out-of-line definition of 'find' does not match any declaration in namespace 'std' in /Users/.../MarkerContainer.h

을 어리석은 실수와 내가하고 싶은 것은 간단하다. 어떤 생각?

미리 감사드립니다. 피에트로

+2

C++ 표준은'std'에서 함수를 만들 수 허용하지 않습니다 네임 스페이스. –

+0

@OliCharlesworth : 일반적으로 네,하지만 당신은 전문화 할 수 있습니다. (이 Q가 전문적이지는 않습니다) –

답변

3

너는 과부하가 허용되지 않는다. find. std 네임 스페이스의 템플릿을 특수화 할 수는 있지만이 경우에는 역 참조 화기에 find_if을 사용하는 것이 훨씬 간단합니다.

// Create DerefEquality comparison (I'll try to come back later and write it). 
container_type::iterator iter = find_if(container.begin(), container.end(), DerefEquality(item_to_find)); 
+0

DeferEquality는 무엇입니까 !!!! ??? – pedr0

+0

오케이! 나는 이해했다! 내 동일한 문제가있는 사람들은 http : //www.cplusplus.com/reference/algorithm/find_if/를 참조하십시오. – pedr0

0

이와 같은 기능을 오버로드 할 수 없습니다. 적절한 네임 스페이스에서 오버로드를 정의해야합니다. 전역 범위에서 네임 스페이스 std을 열어야합니다. 특히 네임 스페이스 std을 사용하면이 작업을 수행 할 수 없다고 생각합니다. 그렇지 않으면 이것이 효과가 있습니다. 말했다

, 난 당신이 적절한 술어 std::find_if()를 사용하는 대신에 당신의 손으로 만들어진 방법을 사용하여보고해야한다고 생각 :

auto it = std::find_if(list.begin(), list.end(), 
         [=](Abelton::Marker* el)->bool { return *el == *check; });