C++ No matching constructor -


recently, i've begun studying c++, , first c++ program - not work.

error message:

no matching constructor initialization of "document".

the ide use xcode.

    class document {      private:      int doc_id;         int lan_id;         std::vector<int>::size_type n_total;         std::vector<int> words;         std::vector<int> counts;          inline int doc_type(){return (counts.empty() && !words.empty())? 1:0;};     public:          document(int docid)         {             doc_id = docid;             n_total = 0;         }         document(int docid, int lanid)         {             lan_id = lanid;             doc_id = docid;             n_total = 0;         }          inline void add(int word, int count)         {             words.push_back(word);             counts.push_back(count);         }         inline void add(int word) { words.push_back(word);}         inline int word(int i) { return words[i]; }         inline int count() { return counts[1];};         inline std::vector<int>::size_type size() {  return n_total;};         inline void setsize(std::vector<int>::size_type total){ n_total = total;};         inline std::vector<int>::size_type  types() { return words.size();}          ~ document()         {             words.clear();             counts.clear();         }     }; 

my guess trying instantiate document class using default constructor, however, not have default constructor defined in code. defined 2 overloaded versions of constructor in public section:

document(int docid, int lanid) 

and

document(int docid) 

if instantiate object follows

document d; 

it give compile error since compiler cannot find default constructor finish creation of object. meanwhile, have defined own constructors, compiler not generate default constructor you.

besides, have several places put redundant semicolons there, error-prone , should not there.

for example:

 inline int doc_type(){return (counts.empty() && !words.empty())? 1:0;};                                                                      //^^^^  inline int count() { return counts[1];};  inline std::vector<int>::size_type size() {  return n_total;};  inline void setsize(std::vector<int>::size_type total){ n_total = total;}; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -