Boost logo

Boost Users :

Subject: [Boost-users] [Fwd: How to print the structure of vector of boost::variant]
From: Baba Prasad (gbabu_at_[hidden])
Date: 2012-01-11 00:09:18


Dear friends,

                  please see the bellow my code and tell me how to get out
this problem please.when I try to print values of
variant it's giving the error as:

std::ostream& operator<<(std::ostream&, const status_rsp&)’:
worked.cpp:33: error: ‘const struct status_rsp’ has no member named ‘os’
worked.cpp:33: error: ‘const class boost::variant<int,
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_, boost::detail::variant::void_,
boost::detail::variant::void_>’ has no member named ‘channelid’
worked.cpp:33: error: expected ‘)’ before ‘;’ token
worked.cpp:34: error: ‘const class boost::variant<int,
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

#include<vector>
#include<iostream>
#include<boost/variant.hpp>
typedef int cid;

typedef int n_queue;
typedef boost::variant<chid> link_st_rs;
typedef std::vector<link_st_rs> link_st_rs_list;

typedef boost::variant<n_queue> link_de_rs;

typedef std::vector<link_de_rs> link_de_rs_list;
using namespace std;

struct lparam {
int value;
};

typedef vector<lparam> link1;
struct link_s_rsp {
link1 ll;
link_st_rs_list lsrl;
link_de_rs_list ldrl;
};

struct status_rsp {

link_s_rsp rsp;
friend std::ostream& operator<<(std::ostream& os , const status_rsp& sr)
{
os << "the value is " << sr.rsp.ll.front().value;
os << "id" << sr.rsp.lsrl.front().chid;
os << "val" << sr.rsp.ldrl.front().n_queue;
return os;
}
};
typedef vector<status_rsp> srl;

int main()
{
linkparam lp;
lp.value =90;

link_de_rs_list ldrl;

lsrl.push_back(4);

ldrl.push_back(3);
status_rsp sr;
sr.rsp.ll.push_back(lp);

srl srl1;
srl1.push_back(sr);

link1::iterator iter2 = srl1.begin()->rsp.ll.begin();

cout << "A vlue is: " << iter2->value;
link_st_rs_list::iterator iter3 = srl1.begin()->rsp.lsrl.begin();
cout << " B value " << iter3->chid;

link_de_rs_list::iterator iter4 = srl1.begin()->rsp.ldrl.begin();
cout << "C value" < iter4->n_queue;

cin.ignore();
return 0;
}

Best Regards
   BaBu

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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