On Mon, 9 Mar 2009, John Peterson wrote:
> Why does it need to be a pointer? AFAICT it was not a constant
> reference so it can be changed at op=. The following test code
> compiles OK for me. The fact that it's a reference reflects the fact
> that the parent of a dense sub matrix/vector should not be NULL; I'd
> like to keep those semantics if possible.
> int main()
> {
> Parent p1(1), p2(2);
>
> Child c1(p1);
> c1.print();
>
> Child c2(p2);
> c2.print();
> c2 = c1;
> c2.print();
p1.value = 3;
c1.print();
c2.print(); // should also be 3 now since c1 and c2 should have the same
parent now.
> return 0;
> }
1
2
1
3
1
That doesn't work. Your assignment operator copies the value that the
reference points to, not the address that is pointed to.
A reference differs from a pointer in two points: (a) it cannot be
NULL, and (b) the address it points to is unchangable.
>> that shouldn't cause any problems, right? Actually, I just implemented this,
>> so if you like it, just check it in.
>
> It looks like the current code handles self-assignment just fine, but
> to be pedantic we should probably check for self-assignment in all our
> operator= calls and return *this if self-assignment occurs.
That is certainly a good concept. Feel free to change my patch in
this sense.
> Also, am I crazy or was there an "Effective C++" about implementing
> copy ctors in terms of assignment operators
Yes, some people are doing it like this.
> (or vice-versa)?
No, that direction is not possible I think since a copy constructor
creates a new object, and in the assingment operator you would have to
assign that new object to an existing object, hence require an
assignment operator.
Best Regards,
Tim
--
Dr. Tim Kroeger
[email protected] Phone +49-421-218-7710
[email protected] Fax +49-421-218-4236
Fraunhofer MEVIS, Institute for Medical Image Computing
Universitaetsallee 29, 28359 Bremen, Germany
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Libmesh-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-devel