I'm still very new to C++, and I'm having issues with allocating heap memory. This is what I have in my header file:
const int NUM_WORDS = 1253;
const int CHAR_SIZE = 256;
class CWords
{
public:
// constructor(s)
CWords();
// destructor
~CWords();
// public member functions
void ReadFile();
const char* GetRandomWord() const;
private:
char* m_words[NUM_WORDS]; // NUM_WORDS pointers to a char
int m_numWords; // Total words actually read from the file
};
I'm trying to allocate space in the implementation cpp file, but I can't (default constructor):
CWords::CWords()
{
m_numWords = 0;
m_words = new char[strlen(m_words) + 1]; // LINE 31
strcpy(m_words, "NULL"); // LINE 32
}
line 31 gives me:
cannot convert 'char**' to 'const char*' for argument '1' to 'size_t strlen(const char*)'
and line 32 gives me:
cannot convert 'char**' to 'char*' for argument '1' to 'char* strcpy(char*, const char*)'
I don't know what these errors mean.