I'm working on a class Word. The objective of the main program is to
open a file (which contains a poem), put the file into a dynamic array
of pointers, which each point to one Word. The pointer to the main
array is wordArr, which is a double pointer. Each node in the array
points to a Word. So it looks like:
WordArr** -> (Word*[0] -> (Word1), Word*[1] -> (Word2), Word*[2] ->
(Word3), etc)
Here is words.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
class Word;
#include "words.h"
#include <iostream>
#include <string>
using namespace std;
string* ptr;
int len;
Word::Word(const string* word)
{
len = word.size();
ptr = new char [len + 1];
strcpy (ptr, word.c_str());
}
Word::~Word()
{
ptr = NULL;
len = 0;
}
char Word::GetFirstLetter()
{
return ptr[0];
}
char* Word::GetWord()
{
return ptr.c_str();
}
|
Words.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <string>
using namespace std;
#ifndef WORD_H
#define WORD_H
class Word
{
private:
string* ptr;
int len;
public:
Word(const string* word);
~Word();
char GetFirstLetter();
char* GetWord();
};
#endif
|
I keep getting this error: "words.cpp:22: error: request for member
‘size’ in ‘word’, which is of non-class type ‘const std::string*’"
What does this mean? How can I fix this?
Any help is appreciated. Thank you!