Boost logo

Boost Users :

Subject: Re: [Boost-users] tuple
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2010-04-23 13:28:11


In article <alpine.LRH.2.00.1004221714070.12496_at_[hidden]>,
jewillco_at_[hidden] says...
>
> On Thu, 22 Apr 2010, luca formaggia wrote:
>
> > Hello,
> >
> > someone could tell me what is wrong in this piece of code
> >
> > #include "boost/tuple/tuple.hpp"
> > using namespace boost::tuples;
> > int main(){
> >         tuple<int, double> t2();
> >         get<0>(t2)=int(10);
> > }
> >
> > I get the following error message:
> >
> > g++ try.cpp
> > try.cpp: In function ?int main()?:
> > try.cpp:5: error: no matching function for call to ?get(boost::tuples::tuple<int, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,
> > boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> (&)())
> >
> > In the tutorial it is written that tuple<int, double> t2() should construct the object via the default constructor.
>
> This syntax is not correct. "tuple<int, double> t2();" declares a
> function named t2 that returns a tuple<int, double>, not an actual tuple.
> Leave off the extra parentheses to get a working version.
>
> > Why I cannot access the first element (it works if I give an initial
> > value, for instance using  tuple<int, double> t2(1);  I get a similar
> > error if I use the method get<N>() instead of the function.
>
> Adding an initial value disambiguates the statement so it is no longer a
> function declaration. The version of get you use does not matter to this
> problem.

Or use initialization syntax:

typedef tuple<int,double> tuple_;
tuple_ t2 = tuple_();

-- 
http://crazyeddiecpp.blogspot.com/

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