octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Explanation of Octave operator overloading


From: John W. Eaton
Subject: Re: Explanation of Octave operator overloading
Date: Fri, 5 May 2006 11:48:59 -0400

On  5-May-2006, John Swensen wrote:

| Thanks for pointing me in the right direction.  That example gave me
| exactly what I needed.  I did find, however, that for simple comparison
| operations, there are macros to make it *really* easy.  The DEFBINOP_OP
| macro allows you to simply implements an accesor function in the
| user-defined type to return some integer value that can then be compared
| against other octave types.  In my case, I have a octave_socket class.
| I used the DEFBINOP_OP macro as follow:
| DEFBINOP_OP (lt, scalar, scalar, <)
| DEFBINOP_OP (le, scalar, scalar, <=)
| DEFBINOP_OP (eq, scalar, scalar, ==)
| DEFBINOP_OP (ge, scalar, scalar, >=)
| DEFBINOP_OP (gt, scalar, scalar, >)
| DEFBINOP_OP (ne, scalar, scalar, !=)
| 
| I then had to overload the scalar_value() method in my user-defined type
| and now I can compare against integers with all the operators.

Do you really need to create a new data type for these functions (and
by "these functions" I mean the normal Unix connect, accept, bind,
listen, etc.)?  Can't you just use an integer for the socket file
descriptor and a structure for the socket address?

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]