\r\n\r\n
Go Back  Xtreme .NET Talk > .NET > Syntax Specific > Visual C# .NET > C# Operator Overloading


\r\n \r\n \r\n \r\n
 
 
Thread Tools Display Modes
\r\n \r\n
\r\n
\r\n \r\n I\'m learning how to do this and I\'m looking to see if I got this correct. Normally when you pass arguments to a function, unless you pass it with the ref or the out keyword, the parameter comes back unchanged, even if you change it in the function, but with operator overloading, even though you don\'t use the ref or the out keyword the parameter you pass are changed, so it has seemed in my testing. If it\'s not how to you pass it by ref; basically this class that I\'m making has to be very fast, creating a copy of the object would waste to much memory so I want to edit the original, I\'ve tried the ref, out, *, & (using unsafe for the last two) and I get all sorts of weird errors, but if you\'re already passing it by ref anyway, then I don\'t really need to use those. Thanks for any help with this. The operator overloading I\'m doing is the !=, +, -, *, and /, it also appears that I need to overload Equals and HashCode by the warnings that come up, is this true or can I simply pass base.HashCode for the HashCode and overload the Equals to do the basic same function as the ==.
\r\n
\r\nThanks again!\r\n
\r\n
\r\n \r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[393682] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 11-24-2003, 05:09 PM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
PlausiblyDamp\'s Avatar\r\n\r\n
\r\n \r\n PlausiblyDamp\r\n PlausiblyDamp is offline\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n \r\n PD - no problem been there myself. I\'m making a 3D vector class... I know .NET isn\'t the ideal environment for that, but it\'s practice and learning more than anything, I got it working but it\'s the semantics I\'m concerned about (programming correct vice incorrectly and working ineffiecently). As you probably know a vector can be added to subtracted and so on.
\r\n
\r\nSo rather than going myVector = new Vector3D(myVector.X += 10, myVector.Y +=10, myVector.Z += 10) I\'m just doing myVector+=10; saves a few steps, horrible example but hoepfully that clarifies what it is I\'m trying to do. Like I said I got it working just setting up the parameter w/o any ref or out, just normal, and it appears it modifies the variable directly, but I just want to make sure, that\'s all.
\r\n
\r\nThanks\r\n
\r\n
\r\n \r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n
\r\n\r\n\r\n\r\n'; pd[393764] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #4  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 11-25-2003, 05:36 AM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
PlausiblyDamp\'s Avatar\r\n\r\n
\r\n \r\n PlausiblyDamp\r\n PlausiblyDamp is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 11-24-2003, 03:03 PM
bri189a's Avatar
bri189a bri189a is offline
Senior Contributor

Preferred language:
C#, VB.NET
 
Join Date: Sep 2003
Location: VA
Posts: 1,004
bri189a is on a distinguished road
Default C# Operator Overloading

I'm learning how to do this and I'm looking to see if I got this correct. Normally when you pass arguments to a function, unless you pass it with the ref or the out keyword, the parameter comes back unchanged, even if you change it in the function, but with operator overloading, even though you don't use the ref or the out keyword the parameter you pass are changed, so it has seemed in my testing. If it's not how to you pass it by ref; basically this class that I'm making has to be very fast, creating a copy of the object would waste to much memory so I want to edit the original, I've tried the ref, out, *, & (using unsafe for the last two) and I get all sorts of weird errors, but if you're already passing it by ref anyway, then I don't really need to use those. Thanks for any help with this. The operator overloading I'm doing is the !=, +, -, *, and /, it also appears that I need to overload Equals and HashCode by the warnings that come up, is this true or can I simply pass base.HashCode for the HashCode and overload the Equals to do the basic same function as the ==.

Thanks again!
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Operator overloading mskeel Random Thoughts 20 03-03-2006 06:47 PM
Operator Overloading in VB 2005 - Dealing with fractions John Tutors Corner 1 01-22-2005 10:44 AM
Overloading? JumpsInLava General 6 04-22-2004 08:53 AM
Overloading and Delegates Jarod Visual Basic .NET 4 05-09-2003 05:49 AM
Operator overloading Morpheus Visual C# .NET 3 02-01-2003 10:20 AM

Advertisement:

Powered by liquidweb