
rajanikanth jammalamadaka [SMTP:rajanik3@rediffmail.com] 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

rajanikanth jammalamadaka [SMTP:rajanik3@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
Hi! Jim, It worked. Thanks, Raj. -- In Boost-Users@y..., "Jim.Hyslop" <jim.hyslop@l...> wrote: 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
participants (2)
-
Jim.Hyslop
-
rajanik3@rediffmail.com