On Aug 28, 10:42 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Subodh" <subodh.bor...@gmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
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
If I use a tracking reference in an API in my C++/CLI program then I
am not able to use this in C# client application it says "function is
not supported by the language "
Consider A and B are two classes in my C++/CLI project
public ref class B
{
const A% B::GetAReference(void)
{
return *m_obj
}
const A^ B::GetAHandle(void)
{
return m_obj;
}
private:
A^ m_aobj
};
now in my C# client:
1. if i use a call to GetAReference() function, I get a compile time
Error: "B.GetAReference() is not supported by the language"
any idea why is this not supported?
2 GetAHandle() works fine, but now the C# client does not treats the
object returned as a constant object whereas in C++/CLI definition I
have mentioned returntype as const handle to A
i.e. it allows me to modify the A object
--- Is there any way to restrict this, I.e. pass a const object to a
C# client App from a C++/CLI function
Any help will be appreciated
Thanks and regards,
Subodh