我遇到了对象功能问题。
我有一个地图作为属性的对象:
#ifndef PARSER_H
#define PARSER_H
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include "../stopwords/stopwords.h"
#include "../porter/porter.h"
class Parser{
private:
unsigned int cant_documentos;
unsigned int cant_terminos;
std::map<std::string,short> dicc_stopwords;
std::map<std::string,unsigned int> hash_frecuencias_globales;
std::map<std::string,std::map<std::string,unsigned int> >hash_frecuencias_locales;
std::map<std::string,std::string> hash_apariciones_unicas;
public:
Parser();
public:
void destroy();
public:
void agregar_termino_a_hash(std::string termino,std::string nombre_archivo);
public:
void cargar_terminos(std::string linea,std::string nombre_archivo);
};
#endif //PARSER_H
#include <iostream>
#include <fstream>
#include <map>
#include <stdlib.h>
#include <string>
#include "parser.h"
#include <string.h>
using std::map;
using std::string;
using std::ifstream;
using std::cout;
using std::endl;
using std::ofstream;
void Parser::agregar_termino_a_hash(string termino,string nombre_archivo){
unsigned int size = termino.size();
if(dicc_stopwords[termino] == 1) return; //No entra porque es un stopword
unsigned int ultimo_char = stem((char*)termino.c_str(),0,size-1);
termino = termino.substr(0,ultimo_char+1);
if(!((*hash_frecuencias_locales)[termino])){
hash_frecuencias_locales[termino] = 1;
if(hash_frecuencias_globales[termino]){
(*hash_apariciones_unicas).erase(termino);
hash_frecuencias_globales[termino]++;
}
else{
cant_terminos++;
hash_frecuencias_globales[termino] = 1;
(*hash_apariciones_unicas)[termino] = nombre_archivo;
}
}else
hash_frecuencias_locales[termino]++;
}
但我不断收到这样的错误:
没有'operator ++(int)'为postfix'++'
声明或类似的东西:
在...中与'operator!'不匹配。
由于
答案 0 :(得分:0)
此行永远不会起作用
if(!((*hash_frecuencias_locales)[termino])){
hash_frecuencias_locales[termino] = 1;
有了这个定义:
std::map<std::string,std::map<std::string,unsigned int> >hash_frecuencias_locales;
我的编译器同意我的意见(在您的文件中进行了一些清理后......)
$ g++ test_map_pb.cpp
test_map_pb.cpp: In member function ‘void Parser::agregar_termino_a_hash(std::string, std::string)’:
test_map_pb.cpp:63:64: erreur: ‘stem’ was not declared in this scope
unsigned int ultimo_char = stem((char*)termino.c_str(),0,size-1);
^
test_map_pb.cpp:68:7: erreur: no match for ‘operator*’ (operand type is ‘std::map<std::basic_string<char>, std::map<std::basic_string<char>, unsigned int> >’)
if(!((*hash_frecuencias_locales)[termino])){
^
test_map_pb.cpp:69:39: erreur: no match for ‘operator=’ (operand types are ‘std::map<std::basic_string<char>, std::map<std::basic_string<char>, unsigned int> >::mapped_type {aka std::map<std::basic_string<char>, unsigned int>}’ and ‘int’)
尝试做一个最小的例子,你会发现你的问题不在你想象的地方。