> Hi All,
>
[quoted text clipped - 7 lines]
> 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
[quoted text clipped - 4 lines]
> 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
Subodh - 28 Aug 2007 19:39 GMT
> > Hi All,
>
[quoted text clipped - 28 lines]
> > 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
Ben Voigt [C++ MVP] - 28 Aug 2007 20:35 GMT
>> > Hi All,
>>
[quoted text clipped - 58 lines]
> Error: "B.GetAReference() is not supported by the language"
> any idea why is this not supported?
Because Microsoft didn't think it was important enough to put in? Or was
potentially too confusing for their target audience for C#, the millions of
VB6 users who did more drag-and-drop than writing code?
> 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
No, the CLR does not implement const-correctness.