WCPtrHash* (Watcom C/C++ Library)

Anyone know how to use WCPtrHash*() (Watcom C/C++ Library) ?
Please tell me using some sample code.


Yoshinobu Seno

Hi!
I have no idea how to use “WCPtrHashDict” class.
Please help!

I made a sinple sample program.

#include <wchash.h>
#include <iostream.h>

static void test1();

// XXXX void data_ptr_prt( unsigned (*hash_fn) (void * key), unsigned =
WC_DEFAULT_HASH_SIZE ){
void data_ptr_prt( void * key, int value){
// cout << “[” << (char *)key << “]\n”; // (int)value<< “]\n”;
}

void main() {
test1();
}
void test1 () {

WCPtrHashDict< char, int > hashdict;

char* key1 = “January”;
char* key2 = “Febrary”;
char* key3 = “March”;
int value1 = 1;
int value2 = 2;
int value3 = 3;

hashdict.insert( key1, &value1 );
hashdict.insert( key2, &value2 );
hashdict.insert( key3, &value3 );

hashdict.find( key1 );
// hashdict.forAll( data_ptr_prt, “”);

}

But, this result is …
Error! cannot generate default
$B!!(Bconstructor to initialize ‘WCPtrHashDict<char*, int>’ since constructors
were declared

Mashine environment :QNX4, WatcomC/C++

Yoshinobu Seno

“Yoshinobu Seno” <seno@fox.omron.co.jp> wrote in message
news:949930$dbc$1@inn.qnx.com

Anyone know how to use WCPtrHash*() (Watcom C/C++ Library) ?
Please tell me using some sample code.


Yoshinobu Seno

Previously, Yoshinobu Seno wrote in qdn.public.qnx4.devtools:

Hi!
I have no idea how to use “WCPtrHashDict” class.
Please help!

I made a sinple sample program.

#include <wchash.h
#include <iostream.h

static void test1();

// XXXX void data_ptr_prt( unsigned (*hash_fn) (void * key), unsigned > WC_DEFAULT_HASH_SIZE ){
void data_ptr_prt( void * key, int value){
// cout << “[” << (char *)key << “]\n”; // (int)value<< “]\n”;
}

void main() {
test1();
}
void test1 () {

WCPtrHashDict< char, int > hashdict;

char* key1 = “January”;
char* key2 = “Febrary”;
char* key3 = “March”;
int value1 = 1;
int value2 = 2;
int value3 = 3;

hashdict.insert( key1, &value1 );
hashdict.insert( key2, &value2 );
hashdict.insert( key3, &value3 );

hashdict.find( key1 );
// hashdict.forAll( data_ptr_prt, “”);

}

But, this result is …
Error! cannot generate default
$B!!(Jconstructor to initialize ‘WCPtrHashDict<char*, int>’ since constructors
were declared

Mashine environment :QNX4, WatcomC/C++

Yoshinobu Seno

“Yoshinobu Seno” <> seno@fox.omron.co.jp> > wrote in message
news:949930$dbc$> 1@inn.qnx.com> …
Anyone know how to use WCPtrHash*() (Watcom C/C++ Library) ?
Please tell me using some sample code.


Yoshinobu Seno

  • “Error! E390: cannot generate default constructor to initialize
    ‘WCPtrHashDict<char,int>’ since constructors were declared”:

If you write ‘WCPtrHashDict< char, int > hashdict;’, it means
(according to any of your favourite C++ books :wink:, that you
want to construct ‘hashdict’ using a parameterless constructor
OR with a constructor declaring all of its parameters with a
default value.

If you do not explicitly declare any constructors for a class,
a parameterless default constuctor can be implicitly generated
for that class.

BUT this can not be done now.

BECAUSE, if you take a look at the definition of WCPtrHashDict
class, you can see, that there are some constructors explicitly
defined, so the implicit parameterless constuctor can not be
generated AND none of the explicitly defined constructors are
parameterless or having all of their parameters declared with
default value, so you simply can not write ‘WCPtrHashDict<
char, int > hashdict;’ to declare an instance of that specific
class…

  • Instead, take a look at the following quick-hacked form of your
    test-code (without any further comments):

#include <wchash.h>
#include <string.h> // strlen()

typedef char* Key_t;
typedef int Value_t;

typedef WCPtrHashDict<Key_t,Value_t> MyHashDict_t;

static unsigned my_hash(const Key_t & key);
static void test1();

void main() {
test1();
}

static unsigned my_hash(const Key_t & key) {
return MyHashDict_t::bitHash(key, strlen(key));
}

void test1 () {
MyHashDict_t hashdict(my_hash);

char* key1 = “January”;
char* key2 = “Febrary”;
char* key3 = “March”;
int value1 = 1;
int value2 = 2;
int value3 = 3;
int *value;

hashdict.insert( &key1, &value1 );
hashdict.insert( &key2, &value2 );
hashdict.insert( &key3, &value3 );

value = hashdict.find( &key1 );
// *value == 1
}

Good luck,
Gyorgy Tamasi (COSY Software)

Hi Tamasi.

Thank you for your reply!
I tried to change a simple sample code in the way of your advice.
I could confirm!


Regards
Yosenobu Seno