I'm making a class for boolean expressions, a simpler version of bool.
I need three operators, one for AND, one for OR and one for NOT.
I can easily make + for OR, by overloading, but how can i declare . for AND and ' for NOT?
Can i even do this?
Thanks in advance
P.S, i'm a beginner :)
No, you can't do this - . and ' aren't overloadable operators. You can overload & for AND and ! for NOT though (and make OR | while you're at it). That way the operators are also consistent with those of the builtin bool type.
PS: How exactly do you want to make your type simpler than bool? What's complicated about the existing bool type?
Operator overloading is a mechanism where you can allow existing operators to be used with your class. You can not add new symbols to be operators, nor change their precidence (order of operations), nor number of parametres. I would love to be able to assign ^ to a higher precidence and use it for exponents, but it is stuck where it is. Most of the existing operators can be overloaded, but some operators can not be overloaded because they 1) are used to define the structure of the class, like ., .*** or **::; 2) require extra parametres to work, like ? :; 3) or has multiple syntaxes with a predefined meaning that makes no sense to change i.e. sizeof.
When looking at your example, I would be looking at using standard logical reductions to make the expression simpler.
(!A && !B) || (B && C)
Apply deMorgan's rule: The intersection (and) of two values is the negation of the union (or) of the negation of the two values.
= !(A || B) || (B && C)
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.