2013-11-29 2 views
0

Это мой файл заголовка:

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


}; 

инициализирую LETTERS_SET под конструктору в моем CPP файле:

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 в PlagiarismDetector.o символ (ы) не найдено collect2: л.д. возвращается статус 1 выхода

Я извиняюсь за вопрос так много вопросов. Любая помощь приветствуется. Вы, ребята, самые лучшие!

ответ

0

LETTERS_SET имеет статическое хранилище, поэтому вам необходимо создать экземпляр его вне функций вашего мембера.

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]); 
} 
Смежные вопросы