|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
i know this may seem really stupid and silly, but i just cant figure
out whats the problem with this coding. any from you guys will be greatly appreciated. thanks ive the header file and the class file which looks like this //IndepHTable.h #ifndef INDEPHTABLE_H #define INDEPHTABLE_H #include <string> #include "List.h" using namespace std; const int TABLE_SIZE=29; class IndepHTable { public: IndepHTable(); //constructor - create empty table ~IndepHTable(); //destructor void put(string word, string def); List get(string word); void print(); private: struct { string word; List defList; } dictionary[TABLE_SIZE]; }; #endif ************************************************** ************************************************** ******** and the class file is this //IndepHTable.cpp #include "IndepHTable.h" #include "List.h" #include <string> #include <iostream> using namespace std; indepHTable::indepHTable() { dictionary.word.clear(); dictionary.defList=NULL; } indepHTable::~indepHTable() { } void indepHTable::put(string word, string def) { } List indepHTable::get(string word) { } void indepHTable::print() { } ************************************************** ************************************************** **** but i get these compiler error saying IndepHTable.cpp:8: error: `indepHTable' has not been declared IndepHTable.cpp:9: error: ISO C++ forbids declaration of `indepHTable' with no t ype IndepHTable.cpp: In function `int indepHTable()': IndepHTable.cpp:10: error: `dictionary' undeclared (first use this function) IndepHTable.cpp:10: error: (Each undeclared identifier is reported only once for each function it appears in.) IndepHTable.cpp: At global scope: IndepHTable.cpp:14: error: expected constructor, destructor, or type conversion before '::' token IndepHTable.cpp:14: error: expected `,' or `;' before '::' token IndepHTable.cpp:19: error: `indepHTable' is not a class or namespace IndepHTable.cpp:24: error: `indepHTable' is not a class or namespace IndepHTable.cpp:29: error: `indepHTable' is not a class or namespace |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
djm wrote:
> i know this may seem really stupid and silly, but i just cant figure > out whats the problem with this coding. any from you guys will be > greatly appreciated. > thanks > ive the header file and the class file which looks like this > > //IndepHTable.h > #ifndef INDEPHTABLE_H > #define INDEPHTABLE_H > > #include <string> > #include "List.h" BTW: why not <list>? > using namespace std; BadIdea(tm). This forces your decision to bring everything from std into the current namespace on everyone using this header. > const int TABLE_SIZE=29; > > class IndepHTable > { > public: > IndepHTable(); //constructor - create empty table > ~IndepHTable(); //destructor > > > void put(string word, string def); > > List get(string word); > > void print(); > > private: > struct > { > string word; > List defList; > } dictionary[TABLE_SIZE]; > }; > #endif > > ************************************************** ************************************************** ******** > > and the class file is this > //IndepHTable.cpp > #include "IndepHTable.h" > #include "List.h" > #include <string> > #include <iostream> > > using namespace std; > > indepHTable::indepHTable() > { > dictionary.word.clear(); > dictionary.defList=NULL; > } > > indepHTable::~indepHTable() C++ is case sensitive. In the header, the name started with a capital "I". > { > > } > > void indepHTable::put(string word, string def) > { > > } > > List indepHTable::get(string word) > { > > } > > void indepHTable::print() > { > > } [snip] Best Kai-Uwe Bux |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Oct 16, 11:43 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> djm wrote: > > i know this may seem really stupid and silly, but i just cant figure > > out whats the problem with this coding. any from you guys will be > > greatly appreciated. > > thanks > > ive the header file and the class file which looks like this > > > //IndepHTable.h > > #ifndef INDEPHTABLE_H > > #define INDEPHTABLE_H > > > #include <string> > > #include "List.h" > > BTW: why not <list>? > > > using namespace std; > > BadIdea(tm). > > This forces your decision to bring everything from std into the current > namespace on everyone using this header. > > > > > const int TABLE_SIZE=29; > > > class IndepHTable > > { > > public: > > IndepHTable(); //constructor - create empty table > > ~IndepHTable(); //destructor > > > void put(string word, string def); > > > List get(string word); > > > void print(); > > > private: > > struct > > { > > string word; > > List defList; > > } dictionary[TABLE_SIZE]; > > }; > > #endif > > ************************************************** ************************************************** ******** > > > > > > > and the class file is this > > //IndepHTable.cpp > > #include "IndepHTable.h" > > #include "List.h" > > #include <string> > > #include <iostream> > > > using namespace std; > > > indepHTable::indepHTable() > > { > > dictionary.word.clear(); > > dictionary.defList=NULL; > > } > > > indepHTable::~indepHTable() > > C++ is case sensitive. In the header, the name started with a capital "I". > > > > > { > > > } > > > void indepHTable::put(string word, string def) > > { > > > } > > > List indepHTable::get(string word) > > { > > > } > > > void indepHTable::print() > > { > > > } > > [snip] > > Best > > Kai-Uwe Bux thanks a lot. thanks for pointing out the probelm, just another thing as you can see in the header file ive added the line struct > > { > > string word; > > List defList; > > } dictionary[TABLE_SIZE]; how can i make the strings null in the constructor? why wont this work? dictionary.word.clear(); dictionary.defList=NULL; thanks |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
djm wrote:
> On Oct 16, 11:43 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote: >> djm wrote: [snip] > just another thing > as you can see in the header file ive added the line > > struct >> > { >> > string word; >> > List defList; >> > } dictionary[TABLE_SIZE]; > > how can i make the strings null in the constructor? > why wont this work? > > dictionary.word.clear(); > dictionary.defList=NULL; Because dictionary is an array. You need to iterate through it and set all pointers to 0. (I think the strings will be constructed empty anyway.) BTW: you should give the struct a name. BTW: you should also give it a constructor so that it can initialize its data properly. Best Kai-Uwe Bux |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Oct 16, 12:26 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> djm wrote: > > On Oct 16, 11:43 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote: > >> djm wrote: > [snip] > > just another thing > > as you can see in the header file ive added the line > > > struct > >> > { > >> > string word; > >> > List defList; > >> > } dictionary[TABLE_SIZE]; > > > how can i make the strings null in the constructor? > > why wont this work? > > > dictionary.word.clear(); > > dictionary.defList=NULL; > > Because dictionary is an array. You need to iterate through it and set all > pointers to 0. (I think the strings will be constructed empty anyway.) > > BTW: you should give the struct a name. > BTW: you should also give it a constructor so that it can initialize its > data properly. > > Best > > Kai-Uwe Bux hmmm then do i actually need a constructor here? cuz 1. the string wil have no initial value? 2. the constructor in List class also makes the contents of "deflist" to NULL |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 2007-10-16 09:57, djm wrote:
> On Oct 16, 12:26 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote: >> djm wrote: >> > On Oct 16, 11:43 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote: >> >> djm wrote: >> [snip] >> > just another thing >> > as you can see in the header file ive added the line >> >> > struct >> >> > { >> >> > string word; >> >> > List defList; >> >> > } dictionary[TABLE_SIZE]; >> >> > how can i make the strings null in the constructor? >> > why wont this work? >> >> > dictionary.word.clear(); >> > dictionary.defList=NULL; >> >> Because dictionary is an array. You need to iterate through it and set all >> pointers to 0. (I think the strings will be constructed empty anyway.) >> >> BTW: you should give the struct a name. >> BTW: you should also give it a constructor so that it can initialize its >> data properly. >> >> Best >> >> Kai-Uwe Bux > > hmmm then do i actually need a constructor here? > cuz > 1. the string wil have no initial value? > 2. the constructor in List class also makes the contents of "deflist" > to NULL No, you should not need a constructor if that is the case. -- Erik Wikström |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Oct 16, 1:20 pm, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2007-10-16 09:57, djm wrote: > > > > > On Oct 16, 12:26 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote: > >> djm wrote: > >> > On Oct 16, 11:43 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote: > >> >> djm wrote: > >> [snip] > >> > just another thing > >> > as you can see in the header file ive added the line > > >> > struct > >> >> > { > >> >> > string word; > >> >> > List defList; > >> >> > } dictionary[TABLE_SIZE]; > > >> > how can i make the strings null in the constructor? > >> > why wont this work? > > >> > dictionary.word.clear(); > >> > dictionary.defList=NULL; > > >> Because dictionary is an array. You need to iterate through it and setall > >> pointers to 0. (I think the strings will be constructed empty anyway.) > > >> BTW: you should give the struct a name. > >> BTW: you should also give it a constructor so that it can initialize its > >> data properly. > > >> Best > > >> Kai-Uwe Bux > > > hmmm then do i actually need a constructor here? > > cuz > > 1. the string wil have no initial value? > > 2. the constructor in List class also makes the contents of "deflist" > > to NULL > > No, you should not need a constructor if that is the case. > > -- > Erik Wikström thanks. it saved a lot of unwanted trouble. ![]() |
|
![]() |
| Outils de la discussion | |
|
|