Boost logo

Boost Users :

Subject: Re: [Boost-users] [proto] vec3 sample error
From: Eric Niebler (eric_at_[hidden])
Date: 2010-11-02 18:23:23


On 11/2/2010 10:14 AM, Kamil Zubair wrote:
> I found a strange error when I try the vec3 sample from proto, my code
> is like this:
<snip>

> int main(int argc, const char* argv[])
> {
> Vec3 a(1, 2, 3);
> Vec3 b(3, 2, 1);
> Vec3 c;
> c = b;
> c.print();
>
> return 0;
> }
>
> I expected that when c is printed it will display 3, 2, 1 ( the value of
> b ) but instead it print 0,0,0 like b is never assigned to c. I try this
> using vs 2010 with boost 1.44 in windows 7 64.

You found a bug in the Vec3 example. The Vec3 class needs a the
following copy assign:

    Vec3 &operator=(Vec3 const &that)
    {
        (*this)[0] = that[0];
        (*this)[1] = that[1];
        (*this)[2] = that[2];
        return *this;
    }

Why? A template operator= is never considered for copy assignment, and
so it finds the one in proto::extends. That one simply creates an assign
tree node which never gets used.

Thanks for the report. I'll fix the example.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.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