CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Posts
    11

    assigning math operators to objects

    I was wondering if there is any way to assign math operators to objects class that I constructed?

    or to construct a math operation from objects. I am coding a Form app that does some pretty complex math and there are visual representations of the math operators for the user to manipulate and create complex math operations with. effectively, I want to have objects that have a complex math operator such as "-(NOT or Negative)" "~ (OR)" ". (AND)" "> (THEN, or IF/Then)".

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: assigning math operators to objects

    Do you think something like this?
    Code:
    public class Foo
      {
        public int v;
    
        public static Foo operator +(Foo a, Foo b)    {
          return new Foo { v = a.v + b.v };
        }
      }
    But I'm not sure if all operators can be defined this way, It seems that only existing binary operators can.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured