dbTalk Databases Forums  

Problem with db_.set_bt_compare(compare_int)

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Problem with db_.set_bt_compare(compare_int) in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Minollo
 
Posts: n/a

Default Problem with db_.set_bt_compare(compare_int) - 11-06-2006 , 11:02 AM






Hi,
i have a problem with Berkeley DB. I try to set

db_.set_bt_compare(compare_int)

in the constructor of MyDb (the same in
db-4.5.20\examples_cxx\getting_started\MyDb.cpp ) first the OPEN
DataBase function but i have the following error:

'MyDb::compare_int': function call missing argument list; use
'&MyDb::compare_int' to create a pointer to member


int MyDb::compare_long(Db *dbp, const Dbt *a, const Dbt *b)
{
long ai, bi;
// Returns:
// < 0 if a < b
// = 0 if a = b
// > 0 if a > b
memcpy(&ai, a->get_data(), sizeof(long));
memcpy(&bi, b->get_data(), sizeof(long));

return (ai - bi);
}

Reply With Quote
  #2  
Old   
Alex
 
Posts: n/a

Default Re: Problem with db_.set_bt_compare(compare_int) - 11-06-2006 , 05:18 PM







Minollo wrote:

Quote:
i have a problem with Berkeley DB. I try to set

db_.set_bt_compare(compare_int)
If you define the compare function inside a c++ class it needs to be a
static function.

So the method signature in MyDb.hpp should be something like:
static int compare_long(Db *dbp, const Dbt *a, const Dbt *b);

The call will be:
db_.set_bt_compare(MyDb::compare_long);

The implementation will be:
int MyDb::compare_long(Db *dbp, const Dbt *a, const Dbt *b)
{
// code here.
return 0;
}

Regards,
Alex



Reply With Quote
  #3  
Old   
Philip Guenther
 
Posts: n/a

Default Re: Problem with db_.set_bt_compare(compare_int) - 11-06-2006 , 07:19 PM



On Nov 6, 3:18 pm, "Alex" <a... (AT) sleepycat (DOT) com> wrote:
....
Quote:
If you define the compare function inside a c++ class it
needs to be a static function.
Actually, it's worse than that: technically you need a function with C
linkage, ala using 'extern "C"', as function pointers for the two may
be incompatible.


Philip Guenther



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.