TextDocsComprLETTERS_SET, referenced from: _ZN12TextDocsCmprLETTER

  • Thread starter Thread starter Jamin2112
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on the initialization error of the static member variable "LETTERS_SET" in the "TextDocsCmpr" class. The user encounters a linker error indicating that "TextDocsCmpr::LETTERS_SET" is not found. The solution provided clarifies that static members must be initialized outside the class definition, which is a requirement in C++. The user is advised to define "LETTERS_SET" in the corresponding .cpp file to resolve the issue.

PREREQUISITES
  • Understanding of C++ class structures and member variables
  • Knowledge of static member initialization in C++
  • Familiarity with C++ standard libraries such as , , and
  • Basic debugging skills for resolving linker errors in C++
NEXT STEPS
  • Research C++ static member initialization best practices
  • Learn about C++ linker errors and how to troubleshoot them
  • Explore the use of C++ standard library containers like and their applications
  • Study advanced C++ class design patterns for better code organization
USEFUL FOR

C++ developers, software engineers, and students learning about class design and static members in C++. This discussion is particularly beneficial for those encountering linker errors related to static variables.

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

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
6K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K