473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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>
& 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>
>::_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?

Sep 5 '06 #1
1 1863
Solved; it's a Koenig lookup problem. :)

Sep 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
6
by: inerte | last post by:
Hello all! I need to build an XML file structure so a client can import data to one of our systems. Totally new to XML, I learned about Namespaces and DTD, and built a nice spec using them. Now...
3
by: Jim Heavey | last post by:
Trying to get the hang of Namespaces. I have primarly developed in VB and am transitioning to C# and the .Net Environment. I have worked a bit with Java as well in school about a year or so ago....
9
by: Patty O'Dors | last post by:
Hi Can somebody please tell me what namespaces are actually for? I notice that when I start a new project in C#, it puts everything in a namespace of the same name as the project. I found them...
17
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
36
by: Wilfredo Sánchez Vega | last post by:
I'm having some issues around namespace handling with XML: >>> document = xml.dom.minidom.Document() >>> element = document.createElementNS("DAV:", "href") >>> document.appendChild(element)...
5
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
6
by: =?Utf-8?B?TUNN?= | last post by:
What is the difference between importing a namespace at the: 1. Project level 2. web.config level 3. Page level What are the requirements/benefits of each? If I import a namespace such as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.