|
Boost Users : |
Subject: Re: [Boost-users] [Fwd: Error while typecasting the boost::variant ( need help)]
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-04-13 16:15:30
On Fri, Apr 13, 2012 at 12:28 PM, Baba Prasad <gbabu_at_[hidden]>wrote:
>
> Dear Friend
>
> due to hurry I did sent proper error message so pls have look now.
>
> my program is
>
>
> typedef std::vector<std::string> vec_name;
>
> struct network
> {
> boost::variant<vec_name> net_id;
> };
>
> typedef std::vector<network>network_list;
>
> // create the instance for vector
>
> network_list net_list;
>
> for(int i=0; i<net_list.size(); ++i)
> {
> unsigned char* query_str = net_list[0].net_id;
> }
>
>
>
>
> ERROR is
> error: cannot convert boost::variant<std::vector<std::basic_string<char>
> > > to unsigned char* in assignment
>
Unless I'm mistaken, to reiterate, *you* need to decide how you want to map
a std::vector< std::string > to an unsigned char*; this has nothing to do
with Boost.Variant. Once you've figured that out, use either
boost::apply_visitor [1] (probably preferred if your actual use case is
more elaborate) or boost::get [2] to apply this mapping on your variant
value.
- Jeff
[1] http://www.boost.org/doc/libs/1_49_0/doc/html/boost/apply_visitor.html
[2] http://www.boost.org/doc/libs/1_49_0/doc/html/boost/get_id1673528.html
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