"TextDocsCompr::LETTERS_SET" ,参考自: _ZN12TextDocsCmprLETTERS_SET$non_lazy_ptr
"TextDocsCompr::LETTERS_SET", referenced from: _ZN12TextDocsCmprLETTERS_SET$non_lazy_ptr
这是我的头文件:
#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]);
}
相关文章:
- 为什么我无法更改"set<set>"循环中的值<int>
- 对于set上的循环-获取next元素迭代器
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 在声明中合并两个常量"std::set"(不是在运行时)
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 将 std::set 与基于键的比较器一起使用
- 如何使用set实现无序数据结构?
- 使用运算符调用 void 函数时出错<set>
- 修改"std::set"中用户定义类型的值
- WinSock Non-Blocking I/O
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 生成提升::hana::set 的常量表达式问题
- 如何在构造函数参数中初始化"std::set"?
- 如何使用 lower_bound/upper_bound 从 std::set 获取索引号?
- 如何在 C++ 中转发声明 std::set?
- 具有std::initializer_list参数的非成员函数(/non构造函数上下文)的重载解析
- 重构使用动态强制转换的 std::set 的比较运算符
- C++ "Invalid use of 'this' in non-member function" ,