"TextDocsCompr::LETTERS_SET" ,参考自: _ZN12TextDocsCmprLETTERS_SET$non_lazy_ptr

"TextDocsCompr::LETTERS_SET", referenced from: _ZN12TextDocsCmprLETTERS_SET$non_lazy_ptr

本文关键字:SET non ZN12TextDocsCmprLETTERS lazy ptr TextDocsCompr LETTERS 参考      更新时间:2023-10-16

这是我的头文件:

#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; 

};

我在cpp文件的构造函数下初始化LETTERS_SET:

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]);
}

但由于某种原因,我得到了以下错误:

"TextDocsCmpr::LETTERS_SET",引用自:__剽窃检测器中的ZN12TextDocsCmpr11LETTERS_SETE$non_lazy_ptr.o找不到个符号collect2:ld返回1退出状态

很抱歉问了这么多问题。非常感谢您的帮助。你们是最棒的!

LETTERS_SET具有静态存储,因此您需要在memeber函数之外实例化它。

std::set<char> TextDocsCmpr::LETTERS_SET;
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]);
}