PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > please
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
please

Réponse
 
LinkBack Outils de la discussion
Vieux 16/10/2007, 07h11   #1
djm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut please

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

  Réponse avec citation
Vieux 16/10/2007, 07h43   #2
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: please

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
  Réponse avec citation
Vieux 16/10/2007, 07h56   #3
djm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: please

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

  Réponse avec citation
Vieux 16/10/2007, 08h26   #4
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: please

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

  Réponse avec citation
Vieux 16/10/2007, 08h57   #5
djm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: please

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

  Réponse avec citation
Vieux 16/10/2007, 09h20   #6
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: please

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
  Réponse avec citation
Vieux 16/10/2007, 09h28   #7
djm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: please

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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h53.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16223 seconds with 15 queries