Dear friends,
Can any one tell me how come out of this problem.
in my big code I am using the following simple code, before I porting in to my project code I were tested like individual module wise but unfortunately the following module is not working , please could any one can help out of this problem.
Thanking you so much , here I have written only single type value but actually in my code multiple values were declared .I will test and I get back to you if any problem.
The boost::get() function is only for getting a value from a variant because variant cannot guess what type to return.
on line 22 you don't need get since the type left of '=' makes clear for the compiler which type to use. Also it's wrongfully used: boost::get<addr>(l1.address = addr); -> boost::get<addr>(l1.address) = addr;
line 19/20 doesn't have anything to do with variants so no boost::get(). The problem is that 'addr' is a type. You cannot access non static members just with the type. In other word you have to instantiate an object and then access the member variables from that object:
Thanks brother for your sharp and powerful answer , I have posted only part of my big code just for the sake of porting into my big code. Actually in my real boost variant have multiple types ( sorry for misunderstanding ).
//...
//*****************************************************
//typedef struct link l1;
// if you thought that l1 in the line above was an object, you shouldn't be using boost.
//*****************************************************
int main()
{
addr a;
a.val=10;
a.type="link";
link l1;
l1.address = a;
//l1.vari.push_back(1);
v& vec = boost::get<V&>(l1.vari) ;
vec.push_back(1) ;
// etc.
Thanks dear friend , It is working fine . but please tell where can I get boost libraries concepts except from boost website , you know in boost website there is no much information about application examples , and many things is not clear , or tell me if any optional suggestions also .
I suggest you to read this tutoriel first: http://www.cplusplus.com/doc/tutorial/
and look at boost in 2 or 3 months when you know how to write proper c++.