c++ - How to instantiate Map within a class? -


i'm making encoding class. failing build. i'm instantiating map within function , getting error message "delete called on 'map::comparator' abstract has non-virtual destructor". ideas how build?

here's header file;

#ifndef _encoding_ #define _encoding_  #include "bstream.h" #include "vector.h" #include "map.h" #include "huffmantypes.h" #include "pqueue.h"   class encoding {  public:     encoding();     ~encoding();      void compress(ibstream& infile, obstream& outfile);     void decompress(ibstream& infile, obstream& outfile);     //map<ext_char, std::string> *referencetable;     std::string compresskey; private:       string filename;     map<ext_char, int> getfrequency(ibstream& infile);     void createhuffman();     //map<ext_char, int> *frequencytable;      huffmanpqueue huffqueue;     //void buildtree();     //void createreferencetable();     //node getnode(node root);     //void tracepaths(node root, string path, int weight);   };  #endif 

here's cpp file:

/**  * file: encoding.cpp  * ------------------  * place encoding class implementation here.  */  #include "encoding.h"  #include "string.h" #include "map.h" #include "strlib.h" #include "huffmantypes.h" #include "pqueue.h"  using namespace std;  encoding::encoding() {  }  encoding::~encoding() {  }  void encoding::compress(ibstream& infile, obstream& outfile) {      map<ext_char, int> frequencytable;      frequencytable = getfrequency(infile);      compresskey = "";       foreach(ext_char key in frequencytable) {          int freq = frequencytable.get(key);          node* newnode = new node;         newnode->character = key;         newnode->weight = freq;         newnode->zero = null;         newnode->one = null;          huffqueue.enqueue(newnode);         string keystring = integertostring(key);         string valstring = integertostring(freq);         compresskey = compresskey + "key = " + keystring + " " + "freq = " + valstring + " ";      }     //buildtree();     //createreferencetable();  }  void encoding::decompress(ibstream& infile, obstream& outfile) {  }  map<ext_char, int> encoding::getfrequency(ibstream& infile) {      map<ext_char, int> frequencytable;      int ch;      while((ch = infile.get()) != eof){         if(frequencytable.containskey(ch)){             int count;             count = frequencytable.get(ch);             frequencytable[ch] = ++count;         }          else {             frequencytable.put(ch, 1);         }     }     frequencytable.put(pseudo_eof, 1);      return frequencytable; } 

the compiler telling you, abstract class map::comparator needs virtual destructor. if delete object through pointer base class, invoke undefined behavior, if base class contains no virtual destructor.

btw: omit empty constructor , destructor class. nervous if read class declaration, seeing destructor, no copy constructor , no assignment operator.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -