Overloading << outputs address and not values?

I have the following friend function in my class header file:
1
2
3
4
5
6
ostream& operator <<(const ostream& osItems, const OListType<T>& items) {
  for(int i = 0;i < 10; i++)
    osItems << items[i] << ", "; 
  osItems << items[count - 1];
  return osItems;
}


And in the program file I have:
 
cout << items;

However, it gives me output like:
 
New list is: 00A0CDEF

Whereas I have a print function set up identically to the overloaded operator, where:
 
items->print();

results in:
 
New list is: 5, 8, 12, 56


Anyone know what would be causing this?
'items' is a pointer, and your << needs a reference. You can change it to take a pointer, or do cout << *items;
Ok, so I changed all instances of cout << items; to cout << *items; and it gives me a fatal error: LNK1120: unresolved externals..
And the unresolved externals are...?
Wow...login issues aplenty today!

1>Program01b.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl <<(class std::basic_ostream<char,struct std::char_traits<char> > &,class OListType<int> const &)" (?<<@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@ABV?$OListType@H@@@Z) referenced in function _main


That's the error I get. However, I don't have a char anywhere near my << overloading function.
I think your function is missing a template <class T>.
Oddly enough....

I changed it to this:

1
2
3
4
5
6
7
8
  friend ostream& operator <<(ostream& osItems, const OListType<T>& list) {
    int i = 0;
  for(i;i < list.count - 1; i++) {
    osItems << list.items[i] << ", ";
  }
  osItems << list.items[list.count - 1];
  return osItems;
}


And it works just fine. I guess it was the .items that was missing?
Topic archived. No new replies allowed.