TextDocsComprLETTERS_SET, referenced from: _ZN12TextDocsCmprLETTER

  • Thread starter Thread starter Jamin2112
  • Start date Start date
AI Thread Summary
The discussion centers around the implementation of the `TextDocsCmpr` class in C++, specifically the handling of the static member `LETTERS_SET`. The user encounters a linker error indicating that `LETTERS_SET` is not found, which is attributed to the incorrect initialization of this static member. It is clarified that static members must be defined outside the class definition, rather than initialized within the constructor. The user is advised to follow proper static member initialization practices, referencing an external tutorial for guidance. The conversation emphasizes the importance of understanding static member behavior in C++ to avoid such compilation errors.
Jamin2112
Messages
973
Reaction score
12
“TextDocsCompr::LETTERS_SET”, referenced from: _ZN12TextDocsCmprLETTER

This is my header file:
Code:
#include <vector>  // std::vector
#include <string> // std::string
#include <fstream> // std::ifstream
#include <set> // std::set

class TextDocsCmpr { 

public: 

    TextDocsCmpr(); 
    ~TextDocsCmpr(); 
    void addFile(std::string); 
    void setThreshold(double); 

private:

    std::vector<std::string> files_vec; 
    std::vector<std::string> get_file_sntncs(std::fstream&);
    std::vector<std::string> get_sntnc_wrds(const std::string&);
    double sntnc_smlrty_qtnt(std::vector<std::string>, std::vector<std::string>);
    static std::set<char> LETTERS_SET;
    double sntnc_smlrty_thrshld; 


};

I initialize LETTERS_SET under the constructor in my cpp file:

Code:
TextDocsCmpr::TextDocsCmpr() { 
    // Set the sentence similarity threshold to a default of 0.7
    sntnc_smlrty_thrshld = 0.7;
    // Add all the characters of LETTERS_ARR to LETTERS_SET
    const char LETTERS_ARR[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
                                           'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
                                           'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 
                                           'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '\'', '.'}; 
    for (int i = 0; i < sizeof(LETTERS_ARR)/sizeof(char); ++i)
        LETTERS_SET.insert(LETTERS_ARR[i]);
}

But for some reason I get the following error:

"TextDocsCmpr::LETTERS_SET", referenced from: __ZN12TextDocsCmpr11LETTERS_SETE$non_lazy_ptr in PlagiarismDetector.o symbol(s) not found collect2: ld returned 1 exit status

I'm sorry for asking so many questions. Any help is greatly appreciated. You guys are the best!
 
Technology news on Phys.org
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
8
Views
2K
Replies
75
Views
6K
Replies
3
Views
2K
Replies
4
Views
4K
Replies
6
Views
2K
Replies
8
Views
6K
Replies
2
Views
2K
Back
Top