printing object of my objectList

hi everybody,
i m having a problem of printing object of my objectList.

In my objectList.hh file i have this:

1
2
3
4
5
6
7
8
9
10
 class stuffList{
   public:
      void printProperties();
      void addMembers(stuff &item);
      stuffList();
   private:
      vector<stuff> elementList;
      int size;

};


and the implimentation i have this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
stuffList::stuffList()
{

}

void stuffList::printProperties()
{
   stuffList::iterator put;

   for (put = elemantList.begin(); put!= elementList.end(); ++put)
   {
      cout << *put<< endl;
   }

}
void stuffList::addMembers(stuff &item)
{
   elementList.push_back(item);
}


but when compiling the stuffList.cc i m having multiple error saying :
stuffList.cc: In member function 'void stuffList::printProperties()':
stuffList.cc:15: error: 'iterator' is not a member of 'stuffList'
stuffList.cc:15: error: expected `;' before 'put'
stuffList.cc:17: error: 'put' was not declared in this scope

please help me and thanks for your replies
Last edited on
Replace stuffList on line 8 with vector<stuff>
i tried that one already and i m having this error:

stuffList.cc:19: error: no match for 'operator<<' in 'std::cout << put.Host::iterator::operator* [with Host = std::vector<stuff>]()'
.../ostream.hh:53: note: candidates are: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(std::basic_ostream<charT, traits>& (*)(std::basic_ostream<charT, traits>&)) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:55: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(std::basic_ios<charT, traits>& (*)(std::basic_ios<charT, traits>&)) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:57: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:58: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(bool) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:59: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(short int) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:60: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(short unsigned int) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:61: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(int) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:62: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(unsigned int) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:63: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(long int) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:64: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(long unsigned int) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:65: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(float) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:66: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(double) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:67: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(long double) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:68: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(const void*) [with charT = char, traits = std::char_traits<char>]
.../ostream.hh:70: note: std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>::operator<<(std::basic_streambuf<charT, traits>*) [with charT = char, traits = std::char_traits<char>]

the line 19 is line 3 on the code below :
1
2
3
4
  for (put = elemantList.begin(); put!= elementList.end(); ++put)
   {
      cout << *put<< endl;
   }

i m so stuck please help
Last edited on
It's complaining because it doesn't know how to print a 'stuff'.
i m a bit lost so i have define a function in class stuff or ...? please point me some where
Last edited on
Your trying to cout an object of type stuff. But it appears you haven't added a method to your stuff class that allows it to be cout'd.

The simpliest method to achieve what you want is to add a function to stuff called print(). Then iterate through your vector and call print on each object.
thanks for your help
hi again,
zaita's explaination is so clear but i m so confused again since i m using this different files i have this:

in stuff.cc
1
2
3
4
void stuff::printProp ()
{
   cout << stuffId << " and " << stuffName << endl;
}

and in stuffList.cc i have this:

1
2
3
4
5
6
7
8
9
10
11
12
 void stuffList::printProperties()
{
//   stuff mystuff;
   vector<stuff>::iterator put;

   for ( put = elementList.begin(); put!= elementList.end(); ++put)
   {
      mystuff1.printProp();
   }

}
 


in the main i have this :
1
2
3
4
5
6
7
  stuffList staffList;
   staffList.addMembers(fs);
   staffList.addMembers(f2);
   staffList.addMembers( f3);
   staffList.addMembers(f4);
   staffList.printProperties();
 


and the output after run is this :

16 and
16 and
16 and
16 and

i really want to know what am i doing thanks in advance
In the for-loop you're always calling mystuff1.printProp(); instead of (*put).printProp();

It seems like stuffID of mystuff1 is 16 and the stuffName is an empty string...
hey thanks mordekai actually i use your and it is printing the all different stuffId
if i understand it good this means that i m using an iterator (put ) to loop over my list and i m using the same iterator to access funtion from my class (stuff).
still i m wondering why i mnot print the string name (stuffName).
i m going to debugge it again

again thanks for your help
Topic archived. No new replies allowed.