2017-03-23 13 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'は何ですか? 'ポイント'の宣言は何ですか? – 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を使用することは非標準です。
関連する問題