2009-08-21 42 views
3

我想創建一個使用LEDA庫的集...我添加了一個類,其中有一個compare()方法在命名空間LEDA下定義的方法...不幸的是,編譯器無法找到這個類比較功能......這裏的錯誤信息......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需要compare()方法爲set的元素來定義。

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

我有這樣的比較方法根據LEDA要求定義...

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 ...但找不到它...

我已經定義了該方法,但不知何故它不被識別?

更新:我似乎有一個附加再現了同樣的錯誤...... 您將需要非常簡單的例子了這個問題,所有compare()定義....包括設置其他類..

+0

請嘗試使該錯誤消息具有一點可讀性。打破它,所以你有一個錯誤每行,並使用代碼格式 – jalf 2009-08-21 23:39:17

+0

對不起...現在修復格式... – badkya 2009-08-22 02:20:06

+0

請添加導致錯誤的代碼。 – Goz 2009-08-22 06:20:03

回答

0

下載LEDA庫的免費版本此..但它是無痛的使用... http://www.algorithmic-solutions.com/leda/ledak/index.htm

這是頭文件... pair.h

#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; 
    } 
}; 

這是主要的C++文件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

好吧,這個bug是不可思議! compare()方法必須在包含LEDA接頭之前定義....