I am making a program that determines if a tweet is happy or sad, and I was thinking I tokenize the tweets, then create a map that stores the word as the key, how many times it was used in total, and how many times it was used in a happy tweet and a sad tweet.
I think this is a good way to go about it, although there may be a better alternative, but I cannot quite understand how to write the Rule of Three for the map I want to create. The Classifier object will be the object used to classify the sentiment of the tweets, and below is the CLassifier.h file, not including additional methods for training data (the DSString object is a character array)
class Classifier {
private:
map<DSString, map<char, float>> *words;
public:
Classifier();
Classifier(const DSString& objToCopy); // Copy Constructor
~Classifier(); // Destructor
Classifier &operator=(const Classifier& objToCopy); // Copy Assignment Overload
}
Below is the CLassifier.cpp file that does not include code for the methods used for training and predicting.
using namespace std;
Classifier::Classifier() {
map<DSString, map<char, float>> *words;
}
// 1/3 Copy Constructor
Classifier::Classifier(const Classifier& objToCopy) {
words = new map<DSString, map<char, float>>(*objToCopy.words);
}
// 2/3 Destructor
Classifier::~Classifier() {
delete words;
words = nullptr;
}
// 3/3 Copy Assignment Operator Overload
Classifier& Classifier::operator=(const Classifier& objToCopy) {
if (this != &objToCopy) {
delete words;
words = new map<DSString, map<char, float>>(*objToCopy.words);
}
return *this;
}
When I try to compile the program, I get an error about my copy constructor saying the following:
Classifier.cpp:15:51: error: definition of implicitly-declared ‘constexpr Classifier::Classifier(const Classifier&)’
15 | Classifier::Classifier(const Classifier& objToCopy) {
What am I doing wrong that I cannot get my program to compile? If I am using maps incorrectly, what can I change to make the program still function? Is there a better/more efficient way to do this? I need to scan a CSV of about 20k tweets.
You have an error in your header file. You used the wrong class name in the copy constructor. You have this:
It should be this: