2017-03-23 1 views
0

이 질문을하는 방법을 생각하는 데 시간이 걸렸습니다. 코드가 너무 커서 중요한 부분 만 사용하려고합니다.참조 객체에 의해 전달 된 변수에 참조 객체가 전달했습니다.

class full_object_detection 
{ 
public: 
    full_object_detection(
     const rectangle& rect_, 
     const std::vector<point>& parts_ 
    ) : rect(rect_), parts(parts_) {} 

    full_object_detection(){} 

    explicit full_object_detection(
     const rectangle& rect_ 
    ) : rect(rect_) {} 

    const rectangle& get_rect() const { return rect; } 
    rectangle& get_rect() { return rect; } 
    unsigned long num_parts() const { return parts.size(); } 

    const point& part(unsigned long idx) const 
    { 
     // make sure requires clause is not broken 
     DLIB_ASSERT(idx < num_parts(), 
      "\t point full_object_detection::part()" 
      << "\n\t Invalid inputs were given to this function " 
      << "\n\t idx:   " << idx 
      << "\n\t num_parts(): " << num_parts() 
      << "\n\t this:  " << this 
      ); 
     return parts[idx]; 
    } 

    point& part(unsigned long idx) { 
     // make sure requires clause is not broken 
     DLIB_ASSERT(idx < num_parts(), 
      "\t point full_object_detection::part()" 
      << "\n\t Invalid inputs were given to this function " 
      << "\n\t idx:   " << idx 
      << "\n\t num_parts(): " << num_parts() 
      << "\n\t this:  " << this 
      ); 
     return parts[idx]; 
    } 

    friend void serialize (
     const full_object_detection& item, 
     std::ostream& out 
    ) 
    { 
     int version = 1; 
     serialize(version, out); 
     serialize(item.rect, out); 
     serialize(item.parts, out); 
    } 

    friend void deserialize (
     full_object_detection& item, 
     std::istream& in 
    ) 
    { 
     int version = 0; 
     deserialize(version, in); 
     if (version != 1) 
      throw serialization_error("Unexpected version encountered while deserializing dlib::full_object_detection."); 

     deserialize(item.rect, in); 
     deserialize(item.parts, in); 
    } 

    bool operator==(
     const full_object_detection& rhs 
    ) const 
    { 
     if (rect != rhs.rect) 
      return false; 
     if (parts.size() != rhs.parts.size()) 
      return false; 
     for (size_t i = 0; i < parts.size(); ++i) 
     { 
      if (parts[i] != rhs.parts[i]) 
       return false; 
     } 
     return true; 
    } 

private: 
    rectangle rect; 
    std::vector<point> parts; 
}; 

typedef vector<long,2> point; 

const full_object_detection& d = dets[i]; //Passed by reference object 

의 출력 :

cout << d.part(41) << endl; // (123,456)

cout << d.part(41).x << endl; // ERROR!

Error C3867 'dlib::vector<long,2>::x': non-standard syntax; use '&' to create a pointer to member 

Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) 

귀하의 도움에 감사드립니다!

+0

'part()'선언은 무엇입니까? 'rect'와'parts'는 무엇에 선언되어 있습니까? 'point'의 선언은 무엇입니까? – EyasSH

+0

@EyasSH 전체 클래스 추가 –

답변

1

Looking at this compiler error more generally 실제로 point::x()은 변수가 아닌 구성원 함수입니다. 그래서 사용해야합니다

cout << d.part(41).x() << endl; // :) 

왜 그렇게 오류가 있습니다? obj.func은 함수 포인터 변수 (예 : &T::func)로 함수를 사용하려는 시도로 볼 수 있습니다. 따라서 다음에 대한 컴파일러 오류가 표시됩니다.

  1. (operator<< 사용) 방법을 알지 못합니다. 최악의 경우 오버라이드가있는 메서드이므로 이름이 모호합니다.
  2. object.MethodName을 사용하는 것은 비표준입니다.
관련 문제