2009-08-21 3 views
3

と比較して、私はLEDAライブラリを使用してセットを作成しようとしています...私は名前空間LEDAの下で定義されたcompare()メソッドを持つクラスの要素を追加してい...残念ながら、コンパイラは見つけることができませんここでは、エラーメッセージがあります...このクラスの機能を比較...C++ LEDAライブラリ

/home/user/Desktop/leda/incl/LEDA/core/set.h: 
In constructor ‘leda::set<E, set_impl>::set() [with E = Operator*, set_impl = leda::avl_tree]’: 
../src/suite.cc:52: instantiated from here /home/user/Desktop/leda/incl/LEDA/core/set.h:71: error: no matches converting function ‘compare’ to type ‘int (*)(class Operator* const&, class Operator* const&)’ 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:351: error: candidates are: int leda::compare(const char&, const char&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:352: error:     int leda::compare(const unsigned char&, const unsigned char&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:353: error:     int leda::compare(const int&, const int&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:354: error:     int leda::compare(const unsigned int&, const unsigned int&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:355: error:     int leda::compare(const long int&, const long int&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:356: error:     int leda::compare(const long unsigned int&, const long unsigned int&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:357: error:     int leda::compare(const float&, const float&) 
    /home/user/Desktop/leda/incl/LEDA/internal/param_types.h:358: error:     int leda::compare(const double&, const double&) 
    /home/user/Desktop/leda/incl/LEDA/core/string.h:382: error:     int leda::compare(const leda::string&, const leda::string&) 

LEDAはsetの要素のために定義されcompare()方法が必要です。私は、これはLEDA要件に従って定義された方法を比較してい

Suite::Suite (set<Operator*> *ops) 
    : operators(ops!=NULL ? ops : new set<Operator*>) 
{ 

...

namespace leda { 
inline int compare (Operator* const &a, Operator* const &b) 
{ 
    return a==b ? 0 : a<b ? -1 : 1; 
} 
}; 

しかし、それはまだここLEDA librabryのset.hでそれを見つけることができません。..

set() { cmp_ptr = compare; } 

それcompare()メソッドへのポインタを見つけようとするとcmp_ptrに割り当てます...しかし、それを見つけることができません...

私はメソッドを定義したが、何とかそれは認識されませんか?

アップデート:私はあなたがする必要があります ...同じエラーを再現はるかに簡単な例を添付

+0

というエラーメッセージが少し読みやすくしてみてください。 – jalf

+0

申し訳ありません...一定の書式設定を書式設定コードを使用することを壊すエラーを引き起こしているコードを追加してください。 – badkya

+0

...あなたは1行につき1個のエラーを持っているし、今 – Goz

答えて

0

..セット内の他のクラスを含むすべてのcompare()の定義....で、この問題を持っているように見えますこれは、メインのC++ファイルです

#include <istream> 
#include <LEDA/core/set.h> 

using leda::set; 

class pair { 
private: 
     int x; 
     int y; 

public: 
    pair() { x = y = 0; } 
    pair(const pair& p) { x = p.x; y = p.y; } 
    pair& operator=(const pair& p) { 
     if(this != &p) { x = p.x; y = p.y; } 
     return *this; 
    } 

    friend std::istream& operator>> (std::istream& is, pair& p) 
    { is >> p.x >> p.y; return is; } 

    friend std::ostream& operator<< (std::ostream& os, const pair& p) 
    { os << p.x << " " << p.y; return os; } 

    pair(int a, int b) { x = a; y = b; } 

    int get_x() const { return x; } 
    int get_y() const { return y; } 
}; 

namespace leda { 
    inline int compare(const pair& p, const pair& q) 
    { 
     if (p.get_x() < q.get_x()) return -1; 
     if (p.get_x() > q.get_x()) return 1; 
     if (p.get_y() < q.get_y()) return -1; 
     if (p.get_y() > q.get_y()) return 1; 
     return 0; 
    } 
}; 

をpair.h ...

このhttp://www.algorithmic-solutions.com/leda/ledak/index.htmは、ヘッダファイルである... ..このためLEDAライブラリーの無料版をダウンロードし、それを使用するの無痛ですpair.cc

#include<pair.h> 

using std::cout; 
using std::endl; 

main() { 

    set<pair> T; 
    cout<<"Hello world"<<endl; 
} 

だけで次のコマンドを使用してコンパイルします。

g++ -I$LEDA_INCLUDE_PATH -I$PATH_TO_PAIR.H pair.cc 
0

[OK]を、バグが変でした!比較()メソッドは、前LEDAヘッダを含むに定義する必要があります....