Having trouble figuring out how to allocate memory for a class array in C++.
Look for the *****. This indicates the line I can't get to work. I included class definitions and the Entry class implementation so you could get a better picture of what things look like. My code is as follows:
class Entry
{
public :
Entry( string word, string def );
~Entry();
string getDefinition( const string &word );
private :
// the privates are up to you
string m_word;
string m_def;
};
private :
Entry *m_dictionary;
int m_numEntries;
};
Dictionary::Dictionary( const string &filename )
{
char buffer[BUFFER_SZ];
char text[INPUT_LINE_MAX_LEN]; // Buffer for each line read in from file
string word;
string def;
ifstream input (filename, ios::in); // Open file for reading
if (input.is_open()) // If the file opened properly perform the following
{
input.getline( text, INPUT_LINE_MAX_LEN);
m_numEntries = atoi(text);
***** m_dictionary = new Entry[m_numEntries](0, 0);