strange error... someone help please///

This is a discussion on strange error... someone help please/// within the C++ Programming forums, part of the General Programming Boards category; hi this is the class, implementation and main of my solution... and the error.. can some one please check it ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    141

    strange error... someone help please///

    hi this is the class, implementation and main of my solution... and the error.. can some one please check it for me and let me know what is the problem? thank you..

    this is the class code

    Code:
    #include <string>
    #include <iostream>
    #include <vector>
    #include "stringset.h"
    
    using namespace std; 
    
    
    class InvertedIndex 
    {
    //insert data member here
      vector <StringSet> list;
    
    public:
     
      // Tally adds one word/file pair to the index 
      void tally(string word, string file);
    this is the implementation code

    Code:
    #include "inverted_index.h"
    #include "osdir.h"
    
    
    int InvertedIndex::size()
    {
        return list.size();
    }
    
    // InvertedIndex::tally
    //   Pre: a word and file pair as strings
    //   Post: adds the file to the index under word
     void InvertedIndex::tally(string word, string file) 
    {
          list.push_back(word);
    }
    and this is main code

    Code:
    #include "inverted_index.h"
    int main() 
    {
    
      StringSet ss;
    
      ss.insert("one");
      ss.insert("two");
      ss.insert("three");
      ss.insert("one");
      
    
      ss.print();
      if ( ss.contains("one") ) 
        cout << "ok - contains('one')\n";
      else
        cout << "fail - contains('one')\n";
       
      // test the InvertedIndex 
      InvertedIndex idx;
      idx.tally("nissan", "car.txt");
      idx.tally("nissa", "carbrand.txt");
      idx.tally("nissan", "everything.txt");
      idx.tally("honda", "hondacar.txt");
    i just want to insert those data into list.....

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,439
    and the error
    What is the error, and how does it not work?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    the error is

    L:\assignment 2\inverted_index.cpp In member function `void InvertedIndex::tally(std::string, std::string)':

    26 L:\assignment 2\inverted_index.cpp no matching function for call to `std::vector<StringSet, std::allocator<StringSet> >:ush_back(std::string&)'

    note L:\Portable\PortableDev-Cpp\Dev-Cpp\include\c++\3.4.2\bits\stl_vector.h:557 candidates are: void std::vector<_Tp, _Alloc>:ush_back(const _Tp&) [with _Tp = StringSet, _Alloc = std::allocator<StringSet>]

    L:\assignment 2\Makefile.win [Build Error] [inverted_index.o] Error 1

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    A vector of StringSets hold StringSets not strings. You seemed to have created (or downloaded, or whatever) the StringSet class with the intention to use it, so I'd say change the string arguement in your tally function to a StringSet.
    Sent from my iPad®

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    ops... ok here is another error...

    class code

    Code:
    #include <string>
    #include <iostream>
    #include <vector>
    #include "stringset.h"
    
    using namespace std; 
    
    
    class InvertedIndex 
    {
    //insert data member here
      vector <string> words;
      vector <StringSet> files;
    
    public:
     
      // Tally adds one word/file pair to the index 
      void tally(string word, string file);
    this is the implementation

    Code:
    #include "inverted_index.h"
    #include "osdir.h"
    
    
    int InvertedIndex::size()
    {
        cout<<"Files size: "<<files.size()<<endl;
        cout<<"Words size: ";
        return words.size();
    }
    
    // InvertedIndex::tally
    //   Pre: a word and file pair as strings
    //   Post: adds the file to the index under word
     void InvertedIndex::tally(string word, string file) 
    {
          words.push_back(word);
          files.push_back(file); //problem occur here
    }
    the main code

    Code:
    #include "inverted_index.h"
    int main() 
    {
    
      StringSet ss;
    
      ss.insert("one");
      ss.insert("two");
      ss.insert("three");
      ss.insert("one");
      
    
      ss.print();
      if ( ss.contains("one") ) 
        cout << "ok - contains('one')\n";
      else
        cout << "fail - contains('one')\n";
       
      // test the InvertedIndex 
        InvertedIndex idx;
      idx.tally("nissan", "car.txt");
      idx.tally("nissa", "carbrand.txt");
      idx.tally("nissan", "everything.txt");
      idx.tally("honda", "hondacar.txt");
                       
                       
      cout <<idx.size() <<endl;
    in the code, i want to store the word and file into vector

    for example

    vector IDX

    --------------------------------------------------------
    nissan | car.txt carbrand.txt everything.txt |
    --------------------------------------------------------
    honda | hondacar.txt |
    ---------------------------------------------------------
    Last edited by peter_hii; 09-27-2006 at 05:31 AM.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    You are doing the same thing again. You are trying to squeeze a string into a vector of StringSet.

    You declare the object files as this:

    Code:
    vector <StringSet> files;
    But then you define tally as this:

    Code:
    void InvertedIndex::tally(string word, string file) 
    {
          words.push_back(word);
          files.push_back(file); //problem occur here
    }
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    so can someone let me know what should i do ? or give me some hints.... please... reallly frustrated on this kinda stuff....

    i am trying really my best to find it out but... end up with smashing my table..

    any help will be appreciated..

  8. #8
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    is there any other way to do it to make it like the list below?

    vector IDX

    --------------------------------------------------------
    nissan | car.txt carbrand.txt everything.txt |
    --------------------------------------------------------
    honda | hondacar.txt |
    ---------------------------------------------------------

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,439
    What are you trying to do?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    just want to insert vector that looks like

    vector IDX

    --------------------------------------------------------
    nissan | car.txt carbrand.txt everything.txt |
    --------------------------------------------------------
    honda | hondacar.txt |
    ---------------------------------------------------------

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    We already gave you the answer. You are passing a string when you should be passing a StringSet object. What else do you want?

    The actual code so that you tell your teacher you did it yourself?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    huh? thnx anyway..

    i am just replying to "laserlight" about - What are you trying to do?
    Last edited by peter_hii; 09-27-2006 at 07:42 AM.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,439
    That's easy enough:
    Code:
    std::vector<std::string> IDX(5);
    IDX[0] = "--------------------------------------------------------\n";
    IDX[1] = "nissan | car.txt carbrand.txt everything.txt |\n";
    IDX[2] = "--------------------------------------------------------\n";
    IDX[3] = "honda | hondacar.txt |\n";
    IDX[4] = "---------------------------------------------------------";
    On a more serious note: one trick to use when debugging is to try and write the smallest and simplest compilable program that demonstrates the error. In this thread, you are pretty much just dumping code at us and expecting us to come up with the solution for you when we cannot even compile the code. Even if we could compile the code, why should we do the intensive debugging work for you? You might as well do it yourself and learn from the experience.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Create an object of type StringSet and give it the word and the file information (presumably it stores strings inside somehow). Then call push_back on the vector with that object so that you are adding a StringSet to the vector.

  15. #15
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by Daved
    Create an object of type StringSet and give it the word and the file information (presumably it stores strings inside somehow). Then call push_back on the vector with that object so that you are adding a StringSet to the vector.
    hi daved .. this is my stringset class

    Code:
    #include <vector>
    #include <string>
    #include <iostream>
    
    using namespace std;
    // StringSet
    //  Class holding a set of strings
    class StringSet 
    {
     private: 
    
      vector <string> contents;
     
     public:
      // insert a value into the set
      // Pre: a string value
      // Post: the value is inserted into the set if it 
      //      is not already present
      void insert(string value);
      
      // test for a value
      // Pre: a string value
      // Post: returns 1 if the value is present in the StringSet, 0 otherwise
      int contains(string value); 
      
      // intersection of this set with another
      // Pre: a StringSet object
      // Post: returns a new StringSet which is the intersection 
      //       of this  with otherset, ie. only the items common to both StringSets
      StringSet set_intersection(StringSet otherset);
      
      // union of this set with another
      // Pre: a StringSet object
      // Post: returns a new StringSet which is the union 
      //       of this  with otherset, ie. the items in either StringSets
      StringSet set_union(StringSet otherset);          
      
      
      // print
      // Pre: None
      // Post: the stringset will be printed to cout
      void print();
      
    };

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 08:32 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  4. Strange response from MSVC
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 04-17-2004, 07:40 AM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21