|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-06-26 07:16:00
The operator << must be defined in the boost namespace.
See the error message of VC:see reference to function template instantiation
'std::basic_ostream<_Elem,_Traits> &boost::operator
<<<char,std::char_traits<char>,std::vector<_Ty>,int,std::string,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>(std::basic_ostream<_Elem,_Traits>
&,const boost::variant<T0_,T1,T2> &)' being compiled
VC looks for boost::operator<< function and not ::operator<< function. But this
should be
documented in OutputStreamable.
This would compile:
#include<iostream>
#include<vector>
#include<string>
#include<boost/variant.hpp>
namespace boost
{
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
{
for(typename std::vector<T>::size_type i = 0; i < v.size(); ++i)
os << v[i] << std::endl;
return os;
}
}
struct TpTemplateVariant
{
typedef boost::variant<std::vector<unsigned long>,int, std::string> BoostVariant;
};
typedef TpTemplateVariant::BoostVariant Tpvariant;
int main ()
{
Tpvariant p(5);
std::cout << p;
return 0;
}
Good Luck,
Ovanes Markarian
On Mon, June 26, 2006 12:45, CLAIRE, Narinder, Group Risk Mgmt wrote:
> I apologise for emailing you directly .. but i canno access the mailing list
> from work..
> However in response to your response.
>
>
> The following doesn't compile either .. I get the error
>
> error C2679: binary '<<' : no operator found which takes a right-hand
> operand of type 'const T0' (or there is no acceptable conversion)
>
> On VC8
>
> #include<iostream>
> #include<vector>
> #include<string>
>
> #include<boost/variant.hpp>
>
>
>
> std::basic_ostream<char> &operator<<(std::basic_ostream<char>
> &theostream,const std::vector<unsigned long> &theVector) {
> for(unsigned long i(0);i<theVector.size();i++)
> theostream << theVector[i] << "\n" ;
> return theostream;
> }
>
>
> struct TpTemplateVariant {
> typedef boost::variant< std::vector<unsigned
> long>,
>
> int,
>
> std::string
>
>> BoostVariant;
> };
>
> typedef TpTemplateVariant::BoostVariant Tpvariant;
>
> int main () {
>
> Tpvariant p(5);
> std::cout << p;
>
> return 0;
>
>
>
>
> ***********************************************************************************
> The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered
Office: 36 St Andrew
> Square, Edinburgh EH2 2YB.
> Authorized and regulated by the Financial Services Authority
>
> This e-mail message is confidential and for use by the
> addressee only. If the message is received by anyone other
> than the addressee, please return the message to the sender
> by replying to it and then delete the message from your
> computer. Internet e-mails are not necessarily secure. The
> Royal Bank of Scotland plc does not accept responsibility for
> changes made to this message after it was sent.
>
> Whilst all reasonable care has been taken to avoid the
> transmission of viruses, it is the responsibility of the recipient to
> ensure that the onward transmission, opening or use of this
> message and any attachments will not adversely affect its
> systems or data. No responsibility is accepted by The Royal
> Bank of Scotland plc in this regard and the recipient should carry
> out such virus and other checks as it considers appropriate.
> Visit our websites at:
> http://www.rbos.com
> http://www.rbsmarkets.com
> ***********************************************************************************
>
Download this as a file
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net