Bit of a long title so I am sorry with that. But I do have a bit of a problem with my code at the moment. It should be pretty general and there is quite a bit going on in the code so I won't post it all but I do have this one problem. Here it is:
Sentence newSentence(currentSentence, this, sentenceCount);
this->sentencesNonP.push_back(newSentence);
Now, newSentence
has an attribute called words
which is of type std::vector<Word *>
, Word
is also another class within the project.
When I am debugging and checking the attributes of newSentence
it shows that words
is populated with a length of 4, however when I check sentencesNonP
, which is a std::vector<Sentence>
, the words
vector length is 0
. I am checking the first point at sentencesNonP
because it is the first the first value being pushed in so it's not that I'm looking at the wrong location of the sentencesNonP
vector.
Any reason why my data is being lost in the conversion process?
EDIT: I have implemented both a =
operator overload and a copy operator. However, words
is still empty in sentencesNonP
.
EDIT2: Sentence.h (excluding include's)
class Word;
class Document;
class Sentence {
public:
//Take out Document * document
Sentence();
Sentence(std::string value, Document * document = NULL, int senNum = 0);
Sentence(const Sentence& newSent);
//Sentence(std::string value);
~Sentence(void);
Sentence & operator=(const Sentence newSent);
Document * getDocument(void);
void setDocument(Document * document);
//__declspec(property(get = getDocument, put = setDocument)) Document * document;
std::string getSentence(void);
void setSentence(std::string word);
//__declspec(property(get = getSentence, put = setSentence)) std::string str;
void setSentenceNumber(unsigned int i);
Word * operator[] (unsigned int i);
unsigned int wordCount(void);
unsigned int charCount(void);
unsigned int sentenceNumber(void);
std::vector<Word *> getWordsVector(void);
private:
std::string sentence;
std::vector<Word *> words;
std::vector<Word> wordNonP;
Document * myd;
unsigned int senNum;
};
Ignore the commented out declspec
EDIT3: Here is my copy constructor:
Sentence::Sentence(const Sentence& newSent) {
this->sentence = newSent.sentence;
this->myd = newSent.myd;
this->senNum = newSent.senNum;
for (int i = 0; i < newSent.wordNonP.size(); i++) {
this->wordNonP.push_back(newSent.wordNonP[i]);
this->words.push_back(newSent.words[i]);
}
}