On Wed, 21 Jan 2009, Marc Dirix wrote:
> Hi,
Hi.
> What is a good / usable example on overloading the + operator?
>
> I need += and + both to work in a class. The added parameter can
> be of type int or string.
Defining lfun::`+() and lfun::``+() should usually be sufficient,
lfun::`+=() is only used when destructive alteration of the object is
allowed (ie the object has a single reference).
> Also what would the `+=() return after doing the operation?
> "this_object()"?
lfun::`+=() should return the result (ie typically this_object()).
Please read
http://pike.ida.liu.se/generated/manual/modref/ex/lfun_3A_3A/_backtick_add_eq.html
for details.
> Currently I get "segmentation fault" which is not really what I want.
You should never get a segfault from pike, what does gdb say?
> --
> Met vriendelijke groet,
>
> Marc Dirix
--
Henrik Grubbström <grubba[at]roxen.com>
Roxen Internet Software AB
|