Connecting Tech Pros Worldwide Help | Site Map

Namespaces when used with ostream_iterators?

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 5th, 2006, 11:45 PM
Robert J. Hansen
Guest
 
Posts: n/a
Default Namespaces when used with ostream_iterators?

In the following code:

=====

#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using std::ostream_iterator;
using std::copy;
using std::cout;
using std::endl;
using std::vector;
using std::ostream;

namespace example {
struct A
{
};
}

ostream& operator<<(ostream& os, const example::A& a)
{
os << "Foo! ";
return os;
}

int main()
{
vector<example::Afoo(1);
cout << foo.at(0) << endl;

// ostream_iterator<example::Abar(cout, "\n");
// copy(foo.begin(), foo.end(), bar);

return 0;
}

=====

I can use the operator<< for the first statement to cout without any
problems. When attempting to use an ostream_iterator and copy() to
achieve the same effect, I get tons of incomprehensible STL errors.
Using gfilt on it--yes, I know gfilt doesn't officially support G++ 4
yet, but I've had good experiences using it to simplify things
nevertheless--I get:

BD Software STL Message Decryptor v2.47a for gcc
stream_iterator.h: In member function 'ostream_iterator<
example::A, char, char_traits<char>
Quote:
& ostream_iterator<example::A, char, char_traits<char>
>::operator=(
const example::A &
)':
[STL Decryptor: Suppressed 4 more STL standard header messages]
test.cc:30: instantiated from here
stream_iterator.h:196: error: no match for 'operator<<' in '*(
(ostream_iterator<example::A, char, char_traits<char *)this
)->ostream_iterator<example::A, char, char_traits<char>
Quote:
>::_M_stream <<
__value'


.... which is still not especially helpful to me.

Can someone help me out with figuring out precisely what invocation I
need to introduce in order to get ostream_iterator to support the
output of namespaced types?


  #2  
Old September 6th, 2006, 04:15 AM
Robert J. Hansen
Guest
 
Posts: n/a
Default Re: Namespaces when used with ostream_iterators?

Solved; it's a Koenig lookup problem. :)

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.