Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10522
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: object copy with reference |
| Date | 2011-09-26 21:02 +0200 |
| Organization | 1&1 Internet AG |
| Message-ID | <j5qi8c$vn4$1@online.de> (permalink) |
| References | <j5n445$knm$1@online.de> <96579252-6676-42c5-ae77-a09ef2a31e91@i28g2000yqn.googlegroups.com> |
On 2011-09-26 10:26:23 +0200, Werner said:
> On Sep 25, 1:43 pm, Philipp Kraus <philipp.kr...@flashpixx.de> wrote:
>> Hello,
>>
>> I need a tip / hint for solving the following problem:
>>
>> I have a class method that is run in different threads:
>> myclass::mythreadmethod( mysuperclass& )
>>
>> mysuperclass is a reference variable, that is used during the thread is
>> running.
>> Anyway the method should be myclass::mythreadmethod( mysuperclass ), so that
>> each running thread has a own local copy of the object, but I can't
>> switch the parameter
>> because the method is derivated of another class.
>>
>> I need in the method a local (deep-copy) of my object. So I create a
>> clone method like
>> myclass::mythreadmethod( mysuperclass& pobj )
>> {
>> mysuperclass& lobj = p_obj.clone();
>>
>> }
>>
>> In this case I get the compiler error, that I try to set up a temporary
>> assignment.
>>
>> The try to do it like
>> myclass::mythreadmethod( mysuperclass& pobj )
>> {
>> mysuperclass& lobj;
>> p_obj.clone(lobj);}
>>
>> create the message l_obj isn't initializate.
>>
>> Does anyone has some tips to create a working solution? The perfect solution
>> should be a deep-copy of the pobj reference
>>
>> Thanks
>>
>> Phil
>
> How about making mysuperclass a pointer (or a smart pointer of some
> kind), then you can initialize it to zero (or in the case of smart_ptr
> it happens automatically). I'd use scoped_ptr in this case..., but as
> example I'd this use a bald pointer...
Thanks, I#M using smart-pointer, i don't see the solution with pointer :-P
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
object copy with reference Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-09-25 13:43 +0200
Re: object copy with reference Victor Bazarov <v.bazarov@comcast.invalid> - 2011-09-25 09:44 -0400
Re: object copy with reference Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-09-25 16:25 +0200
Re: object copy with reference Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-09-25 17:59 +0200
Re: object copy with reference Goran <goran.pusic@gmail.com> - 2011-09-26 00:27 -0700
Re: object copy with reference Qi <no@no.no> - 2011-09-26 15:51 +0800
Re: object copy with reference Werner <werasm@gmail.com> - 2011-09-26 01:26 -0700
Re: object copy with reference Werner <werasm@gmail.com> - 2011-09-26 01:32 -0700
Re: object copy with reference Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-09-26 21:02 +0200
Re: object copy with reference Werner <werasm@gmail.com> - 2011-09-26 23:34 -0700
Re: object copy with reference Werner <werasm@gmail.com> - 2011-09-27 02:08 -0700
Re: object copy with reference SG <s.gesemann@gmail.com> - 2011-09-27 04:10 -0700
Re: object copy with reference Werner <werasm@gmail.com> - 2011-09-27 06:56 -0700
csiph-web