please help

D

djm

i know this may seem really stupid and silly, but i just cant figure
out whats the problem with this coding. any help 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
 
K

Kai-Uwe Bux

djm said:
i know this may seem really stupid and silly, but i just cant figure
out whats the problem with this coding. any help 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 said:
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
 
D

djm

djm said:
i know this may seem really stupid and silly, but i just cant figure
out whats the problem with this coding. any help 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 said:
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()

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
 
K

Kai-Uwe Bux

djm said:
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
 
D

djm

djm said:
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
 
G

Guest

djm said:
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.
 
D

djm

djm 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.

thanks. it saved a lot of unwanted trouble. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top