When I try to print the content of vector of structure of variant of vector the following big unbelievable error even it is very simple.
#include<iostream>
#include<boost/variant.hpp>
#include<vector>
#include<string>
usingnamespace std;
typedef std::string net_id;
typedef std::vector<net_id> netwk_id;
struct network
{
boost::variant<netwk_id> _netwk_inc;
};
typedef vector<network> network_list;
int main()
{
netwk_id net1;
net1.push_back("202");
network net2;
net2._netwk_inc = net1;
network_list net3;
net3.push_back(net2);
for(int i =0; i< net3.size(); ++i)
{
cout << net3[0]._netwk_inc ;
}
}
Error;
In file included from /usr/include/boost/variant/variant.hpp:1892:0,
from /usr/include/boost/variant.hpp:17,
from bin_query.cpp:2:
/usr/include/boost/variant/detail/variant_io.hpp: In member function ‘void boost::detail::variant::printer<OStream>::operator()(const T&) const [with T = std::vector<std::basic_string<char> >, OStream = std::basic_ostream<char>]’:
/usr/include/boost/variant/variant.hpp:858:32: instantiated from ‘boost::detail::variant::invoke_visitor<Visitor>::result_type boost::detail::variant::invoke_visitor<Visitor>::internal_visit(T&, int) [w
I don't see a problem here to be solved. I see an unindeted code messed up with text and I don't know where to look to tell you where the problem comes from. I'm so sorry.
Sort out your code, use indents, and write a comment beside the place where the error occures, so that people can help you.
When I try to print the content of vector of structure of variant of vector the following big unbelievable error even it is very simple.
#include<iostream>
#include<boost/variant.hpp>
#include<vector>
#include<string>
usingnamespace std;
typedef std::string net_id;
typedef std::vector<net_id> netwk_id;
// Structure to hold the vector of netid's and some more information that I am not included here bcz it is //similar one.
struct network
{
boost::variant<netwk_id> _netwk_inc;
};
// Here I am making vector containing the above structure // this vector only available at other side //meaning I am sending this vector through socket programming to some other server so that there I //have to decode or extract this information.
typedef vector<network> network_list;
int main()
{
// here I am assigning my netid to vector
netwk_id net1;
net1.push_back("202");
// here I am assigning vector to structure variable of type boost variant
network net2;
net2._netwk_inc = net1;
// finally I am pushing structure into vector
network_list net3;
net3.push_back(net2);
// Now see here i am trying to print the content of vector what ever may be I assigned earlier . but here //only it is showing error
// I don't know exactly how to extract the content
for(int i =0; i< net3.size(); ++i)
{
cout << net3[0]._netwk_inc ;
}
}