Re: Passing const objects as arguments to function or return types

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Subodh" <subodh.borker@xxxxxxxxx> wrote in message
news:1188322141.463099.213360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi All,

In C++ we could pass a constant reference to a function so that the
target function could not modify the objects passed
eg. const classA & dummmyfunction(const classB)
similar thing was valid for objects passed with pointer to constant
objects

In C++/CLI is there any way for imitating this, I want to pass
arguments to and return value from my member function as a constant
objects.

Sadly no, the compiler throws an error as soon as you try to declare const
member functions, so passing handles to const is pretty useless: you can't
even read properties.


currently i am passing a handle to the object to client (consumer)
function which then can easily modify the object received

I had one more doubt about C++/CLI
In C++/CLI Handles are similar(may be not not equivalent) to that for C
++ pointers
Is there any operator that is equivalent to C++ References (&) in C++/
CLI

The tracking reference (%) is the version of the C++ reference that supports
garbage collection


any help will be appreciated

Thanks and Regards,
Subodh



.



Relevant Pages

  • Re: accessor member functions and const
    ... I want to be able to reference the returned ... const int& getValconst ... so one cannot modify the object via the reference. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: accessor member functions and const
    ... > reference the returned value v. ... int& val ... const int& valconst ... so one cannot modify the object via the reference. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: using const & in function prototypes
    ... passing a built-in type by 'const&' just doesn't make ... are free to pass by value, by reference, or by pointer. ... you can pass 'const' or not. ... matter for the caller. ...
    (microsoft.public.vc.language)
  • accessor member functions and const
    ... I want to be able to reference the returned ... expression of type 'const int' ... so one cannot modify the object via the reference. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: const &
    ... Again, I'm not sure if I got correctly, but what I meant that the compiler ... reference (Deceived by the fact that the function won't change the const ... > passing reference. ...
    (microsoft.public.vc.language)