Jay said:
Edward,
My mistake, I read your question as wanting the names, not the
signatures.
No, the signatures. The MSDN doc on Managed C++ doesn't have that
information.
I haven't tried it, An easy way to get this signatures may be to
simply define all the operators in a C# project, reference this
project in your Managed C++ project, then use object browser, to see
the syntax, or use ILDASM to see the syntax.
I found the signatures in one of the online articles you mentioned. I am
going to pick up Richard Grimes' book on Managed C++ today. Although the
MSDN docs on it are decent, there are too many incomplete areas and, aside
from this thread, most of my other queries on this NG have gone unanswered.
Reading the various links I gave, specifically the Managed C++ spec
page, I would agree with that statement.
However in another part of the MSDN doc, it is suggested that if the
signature were changed to use references, then the infix notation in __gc
classes would work. Trying to figure out what is true or not regarding this
is a PITA. Furthermore my code is a component and needs to be CLS compliant.
The doc for Managed C++ is almost completely vague on what __gc class member
function usages are CLS compliant or not. This is easily the weakest part of
the doc. Evidently attempting to write .NET components in MC++, rather than
MS's darling C#, was something that MS doesn't encourage greatly.
However if you do define the op_XXX in the correct format, then those
routines are usable for other language such as C# & VB.NET (VB.NET the
Whidbey edition). Seeing as most of my managed C++ would be for
libraries to be consumed by C# or VB.NET, this makes sense to me. I
do agree, if I were attempting an entire Managed C++ solution, this
may get really annoying, really quick! ;-)
See above. Yes, I want to define it in the correct format, if I only knew
what that is for MC++. I have gathered, unless I am greatly wrong, that
using __gc pointers in MC++ is the same as using object references in C#. So
if one uses references instead in MC++, I gather that this is not CLS
compliant since it has no analogy to anything in C# and CLS.
I'm really curious as to why one needs to use the op_XXX syntax as
oppose to the normal operator+ syntax. I would expect in a __gc class
that operator+ (or __gc operator+) would create the proper routine
with the proper parameters, and then the rest of your code would work
as one would expect!
Definitely not according to the docs. Using any C++ operator syntax is
forbidden in __gc classes. Some of the other things that are forbidden are
really strange. For instance one can't use const data members in __gc or
__value classes. I guess if one would normally have a const data member in a
__gc/__value class, one needs to create a read-only property instead. I am
still trying to figure out whether passing a const T __gc * is CLS compliant
but I expect not. In that case how does one pass an __gc object which is not
to be modified ? These limitations are gnarly problems for standard C++
programmers who are use to much greater flexibility in their programming
paradigms.
I have not looked at the Whidbey version of C++ to know if MS has
improved this yet or not...
There is a new binding for MC++ called CLI, with Herb Sutter being the chief
architect of that. How that will eventually change MC++ -> CLI remains to be
seen.
Reading the Managed C++ spec page I gave in my other post, I get the
impression this should be:
For a __value class, yes. For a __gc class I am still not sure whether
references can be used instead of pointers. See above.
I do hope the Grimes' book clears up many things. My previous reading of his
ATL books indicates that he is a very good amd thorough technical writer, in
that stratosphere ot technical writing ability about MS technologies that
Richter and very few others inhabit. So I hope I am not disappointed.
Hope this helps
Jay
Edward Diener said:
Jay B. Harlow [MVP - Outlook] wrote:
Edward,
Where in these .doc files is the information ?
Partition I Architecture
9.3 Operator Overloading.
Did you check the table of contents?
Hope this helps
It does. However it appears that defining operators for MC++ __gc
classes/structs does not really work:
_gc class AC
{
public:
static bool op_Equality(AC * first,AC* second)
{ bool ret; /* some code which sets ret based on values in each AC
*/ return(ret); }
};
AC * fac = new AC();
AC * sac = new AC();
// Code which changes some values in each AC etc.
if (fac == sac) { } // Compares the pointers, not the values
if (*fac == *sac ) { } // Does this match my op_Equality above ? I
think not.
It would have been better if op_Equality ( and binary operators in
general ) for __gc classes/structs had the signature instead of:
static bool op_Equality(T & first,T & second);
then "if (*fac == *sac ) { }" would work. Because of this,
implementing the operators using the op_XXX seems to be a waste of
time. The only advantage in doing so for __gc classes/structs is
that the user can call op_XXX directly instead of using infix
notation.