boost::variant output a vector?
Dear list,
In the manual of boost::variant:
OutputStreamable: For any object t of type T, std::cout << t must be a
valid expression.
However, I can not output a variant vector work by defining ostream&
operator<< vector<double> . Attached is a test case. Note that variant
int, string can be outputed, but not the vector. Yet, cout <<
vector<double> is working.
I am using gcc 3.2.2 on linux redhat 9.
Many thanks in advance.
Bo
#include "boost/variant.hpp"
using namespace std;
#include <string>
#include <vector>
typedef boost::variant
Hi! Bo Peng wrote:
However, I can not output a variant vector work by defining ostream& operator<< vector<double> . Attached is a test case. Note that variant int, string can be outputed, but not the vector. Yet, cout << vector<double> is working.
The problem is not in the variant itself, but it the function lookup of C++: Your operator << is neither defined in the namespace of the ostream (which is std::) nor defined in the namespace from where it is called (which is boost::). That's why the compiler does not find your function when using the variant. You must not put anything into the std namespace but function overloads AFAIK. So try to put your operator << into the namespace std. You can search throu the newsgroup comp.lang.cpp.moderated for further information. Frank
participants (2)
-
Bo Peng
-
Frank Birbacher