insertion operator overloading error

Dear friends,
Please look my code and when I trying to print the values of structure "status_rsp" using insertion operator overloading but it is giving "error as " no match operator << .

how to print value by using insertion operator overloading , because here ie in this sample code without overloading also printing but this is the piece of or sample of code , so once I executed there it is giving error as " no match operator for <<..

please any one tell me how to get out of this problem.


code:


#include<vector>
#include<iostream>
using namespace std;

struct linkparam {
int value;
};

typedef vector<linkparam> link1;
struct link_status_rsp {
link1 ll;
};

struct status_rsp {
link_status_rsp rsp;
friend std::ostream& operator<<(std::ostream& os , const status_rsp& sr)
{
os << "the value is " << sr.rsp.ll.begin();
return os;
}
};
typedef vector<status_rsp> srl;

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

//Node1
status_rsp sr;
sr.rsp.ll.push_back(lp);


//Node2
srl srl1;
srl1.push_back(sr);

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

//list Destination value
cout << "A vlue is: " << iter2->value;

cin.ignore();
return 0;
}

The problem is os << "the value is " << sr.rsp.ll.begin();
I'm not sure what you're trying to do. begin() returns an iterator which cannot be printed. Maybe you wanted ...front().value instead?
Dear friend , thanks for your kind help , so it is working fine.

the actual code look like bellow code. so when i try to run the following code it is giving the big error message regrading boost variant please any one could help me to get out of this problem.


just what i want is assign a values to structure status_rsp made up other structure which intern contain multiple vectors. pls see my code..
#include<vector>
#include<iostream>
#include<boost/variant.hpp>
typedef int channelid;

typedef int num_queue;
typedef boost::variant<channelid> link_st_rs;
typedef std::vector<link_st_rs> link_st_rs_list;

typedef boost::variant<num_queue> link_de_rs;

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

struct linkparam {
int value;
};

typedef vector<linkparam> link1;
struct link_status_rsp {
link1 ll;
link_st_rs_list lsrl;
link_de_rs_list ldrl;
};

struct status_rsp {


link_status_rsp rsp;
friend std::ostream& operator<<(std::ostream& os , const status_rsp& sr)
{
os << "the value is " << sr.rsp.ll.front().value;
os << "fdsf" << sr.rsp.lsrl.front().channelid;
os << "fewf" << sr.rsp.ldrl.front().num_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->channelid;

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

cin.ignore();
return 0;
}


error I am getting is :
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
Why would you assume that variant has members named after types it contains? I haven't used boost::variant, so you'll have to find yourself how to properly use it. See http://www.boost.org/doc/libs/1_35_0/doc/html/variant/tutorial.html

Also, http://cplusplus.com/articles/z13hAqkS/
Last edited on
Topic archived. No new replies allowed.