Re: "pointers" in /clr



Hey Peter

Just want to add that ref classes also don't get a default assignment
operator.

--
Regards,
Nish [VC++ MVP]


"Peter Oliphant" <poliphant@xxxxxxxxxxxxxxxx> wrote in message
news:etNzUuh6FHA.2552@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Holger,
>
> In fact, the reason I asked was because I needed to create a copy
> constructor and I couldn't without knowing these syntax 'equivalences' to
> 'pointer' and 'contents of'... : )
>
> That is, I didn't know this is the form of a copy constructor for a ref
> class:
>
> ref class refClass
> {
> refClass( refClass% other ) {}
> } ;
>
>
> [==P==]
>
> "Holger Grund" <hg@xxxxxxxxxxxxxxx> wrote in message
> news:eNdNfbg6FHA.2576@xxxxxxxxxxxxxxxxxxxxxxx
>> "Peter Oliphant" <poliphant@xxxxxxxxxxxxxxxx> wrote
>>
>>> ref class myClass() {...} ;
>>>
>>> myClass i ;
>>> myClass^ i_ptr = &i ; // error, use what instead of '&'?
>> myClass^ i_ptr = %i;
>>
>>> myClass j = *i_ptr ; // error (i think), do what instead?
>>>
>> That's fine, so long as a copy ctor is defined. C++/CLI
>> does _not_ automatically define copy ctors for ref classes
>> * sigh *.
>>
>> If you want
>> the equivalent to a C++ reference (int%) you can write
>> myClass% j = *i_ptr;
>>
>> -hg
>>
>
>


.



Relevant Pages

  • ref classes and value classes
    ... "ref class". ... ref class RefClass ... value class ValClass ... // create val on the managed heap ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Remoting and DataSets
    ... Also, you can only use a default constructor, so you can't pass an itialising value to the object constructor either. ... the business libraries to the list of ref in the client app project. ... I not supposed to add the ref at all, and use relection all the way to ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: GetConstructor does not work when the constructor has ref paramete
    ... it's very rare to need "ref" in a constructor (and I'd ... public class MyClass ... Type type = typeof; ...
    (microsoft.public.dotnet.general)
  • Re: Form constructor taking parameters by reference
    ... | "ref" keyword. ... IIRC the form constructor by default takes no parameters. ... Ignacio Machin ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why do I need a copy constructor?
    ... Are these ref or value classes or just native classes? ... You don't need a copy constructor. ... Is B complete at newB (i.e. is the class body for it ... The compiler does not generate a copy ctor for ref classes. ...
    (microsoft.public.vc.language)

Loading