Boost logo

Boost Users :

From: rajanik3_at_[hidden]
Date: 2001-10-19 14:34:27


Hi! Jim,
It worked.
Thanks,
Raj.
-- In Boost-Users_at_y..., "Jim.Hyslop" <jim.hyslop_at_l...> wrote:
> rajanikanth jammalamadaka [SMTP:rajanik3_at_r...] wrote:
> > Hi! Jim,
> > Could you please tell me why this code is not working:
> >
> > #include <iostream>
> > #include <boost/any.hpp>
> > using namespace boost;
> > int main()
> > {
> >
> > any holdsanything ;
> > holdsanything = 9;
> > std::cout<<holdsanything<<endl;
> > holdsanything = std::string("hello");
> > std::cout<<holdsanything<<endl;
> > return 0;
> > }
>
> Hi, Raj
>
> You didn't specify what problems you were having. Am I correct in
assuming
> you get a compiler error on the std::cout lines? If so, then the
problem is
> that class 'any' does not have an extraction operator defined. If
you change
> the lines to:
>
> std::cout << any_cast<int>(holdsanything)<<std::endl;
>
> and
>
> std::cout << any_cast<const char *>(holdsanything) << std::endl;
>
> it should work properly.
>
> --
> Jim


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