|
-
December 17th, 2008, 09:10 PM
#1
Operator overloading
Say I wanted to override the '+' operator for the following class:
Code:
public class MyClass
{
private MyType _mySecretInternalRepresentation; // MyType maybe UInt32 for example
public static MyClass operator+(MyClass a, MyClass b)
{
// code required here
}
}
Ok, *I*know how to add a to b, but how can i get at their internal representation so I can perform the add, without exposing the internal representation (making it public) to everyone and breaking one of the fundamental laws of OO ?
Am I missing something? I'm sure in C++ I had access to private members of the *same* class within an operator overload function.
Microsoft give an example in the documentation (see operator overloading C# vs Java) for complex numbers, but their ComplexNumber class has public members which is not good because individual parts of the complex number can be modified independently by external code.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|