Click here to Skip to main content
15,891,864 members
Everything / Operators

Operators

operators

Great Reads

by Muraad Nofal
A haskell monad/(applicative)functor like interface in C# that extends IEnumerable.
by Coral Kashri
Fold-expressions in extreme cases
by Thomas Daniels
This article explains how bitwise operators work and this article explains also several purposes of them with examples in C# and VB.NET.
by Yvan Rodrigues
Maybe writing a tip will mean the last time I fall for this.

Latest Articles

by Coral Kashri
Fold-expressions in extreme cases
by Thomas Daniels
This article explains how bitwise operators work and this article explains also several purposes of them with examples in C# and VB.NET.
by yash soman
The tip is about using Elvis operator which is introduced in C# 6.0 for Null Reference Checks. It gives an example of how to use it.
by Yvan Rodrigues
Maybe writing a tip will mean the last time I fall for this.

All Articles

Sort by Score

Operators 

18 Sep 2013 by Muraad Nofal
A haskell monad/(applicative)functor like interface in C# that extends IEnumerable.
14 Oct 2013 by Philippe Mori
The "good" way to define operator, is to define them so that it match (as much as possible) what would happen with built-in types.For binary * operator, usually you should do it this way:class Rationnal{public: Rational& operator*=(const Rational &rhs) { a *= rhs.a; b...
22 Oct 2013 by CPallini
It is inherited but hidden, see the answer to this Stack Overflow question: "operator= and functions that are not inherited in C++?"[^].
22 Oct 2013 by Sergey Alexandrovich Kryukov
It is of course inherited as everything. The only problem is that the operator you defined is hidden by the default operator. You can easily see it if you cast a to Foo. Also note that Foo "=" returns the type Foo, and your code would require it to return Bar. There is no such operator, and this...
8 Feb 2016 by nv3
If that is the exact wording of the question then it's a trap. C++ does not allow to override the behavior of arithmetic operators between predefined types, for example int and char*. That's what the error message C2803 is telling you, and the compiler is correct in this case.So what can you...
28 May 2020 by CHill60
Your concept of how to parse the calculator text seems a little strange If CalculatorText.Text.Contains("-") Then Substract = CalculatorText.Text.Split("-") For Each NumToPower As String In Substract ...
21 Apr 2013 by Naz_Firdouse
please check this...http://stackoverflow.com/questions/4091831/how-to-use-ternary-operator-in-razor-specifically-on-html-attributes[^]
14 Nov 2015 by Richard MacCutchan
See https://www.google.com/search?q=operator%20overloading%20c%2B%2B[^].
18 Feb 2018 by Maciej Los
Assuming that a, b and c are lengths of sides of triangle, you can't create a triangle from 1, 2, 3! Check this: How to Determine if Three Side Lengths Are a Triangle: 6 Steps[^] In other words: TriangleIsPossible = (a+b>c && a+c>b && b+c>a)
14 Aug 2020 by Jon McKee
It's the format of a for-each[^] loop in Java. It reads as "for each string myInt in strArrayList".
19 Feb 2013 by Arun1_m1
create table #bitoprt(id int identity(1,1),bag bit,tapee bit,band bit,knife bit,guitar bit,watch bit,umbrella bit,hammer bit)insert into #bitoprtvalues(0, 1, 1, 0, 1, 1, 1, 0), ( 0, 1, 1, 0, 1, 1, 0, 0), ( 0, 1, 1, 0, 0, 0, 0, 0)select (bt.bag...
5 Mar 2013 by OriginalGriff
You can provide AND, OR, and NOT operators for your own class: http://msdn.microsoft.com/en-us/library/5tk49fh2(v=VS.80).aspx[^] but you can't define new operators. You can't extend the language, which is what that would require. (Well, you could with careful use of #DEFINE but the result would...
12 Jul 2013 by OriginalGriff
All a lambda is, is a method that has been "stretched out".x => x + 1;Is the equivalent of writingprivate int MyMethod(int x) { return x + 1; }There is a lot more to them than that when you come to using them (the whole of Linq depends on them for example) but for proper...
14 Oct 2013 by Stefan_Lang
Thedre's some invalid code in your example, as well as bits that won't be useful: Rational operator*(Rational& rhs); //The same as below but differs in returned value type(1) Rational operator*(Rational rhs);(2) Rational& operator*(Rational rhs); //This will throw an error of...
28 Nov 2013 by C For Code!!!
"~/cancellation.aspx?Registrat...
3 Feb 2014 by Dave Kreskowiak
There's no way to change the behavior of IsSymbol.So, you're going to have to write your own method to determine what's acceptable and what's not. Instead of black-listing known characters, use a white-list instead. Accept only the characters you want instead of trying to filter out all...
6 Feb 2016 by OriginalGriff
I don't think you want to do that: it's very counter-intuitive.Normally, when you add an integer and a pointer, you get a pointer that has moved on within the memory pointed to by the original pointer: char *c = new char[10]; cin >> c; // abcdefg c = c + 2; cout
23 Jun 2016 by Maciej Los
Replace that:GetVo(string fdate, string tdate, string region)withGetVo(DateTime fdate, DateTime tdate, string region)Above means: use proper data types!Then improve where statement this way:where Reg.Region == region && vv.VName != "" && Reg.StartDate >= fdate && Reg.StartDate...
31 Jan 2017 by KarstenK
It is correct by your code:T2 = ++(++T1);1. you increment the T1 in the braces2. you increment the T1 outside the braces3. you assign the T1 values to T2tip: use a debugger to step into the three function calls of this code line.
14 Aug 2020 by Richard MacCutchan
See The Java™ Tutorials[^]
11 Oct 2012 by Muhammad Idrees GS
Hi, I am working on a chess application and need to create opening book, a file which could contains a millions of moves and positions. we have 64 squres, some of which have occupied by pieces while some are empty. Let we represent our pieces with following bits (using to Huffman encoding...
11 Oct 2012 by Frederico Barbosa
Try this website:http://stackoverflow.com/questions/1831386/programmer-puzzle-encoding-a-chess-board-state-throughout-a-game[^]and more specifically this one:http://www.cforcoding.com/2009/12/programming-puzzles-chess-positions-and.html[^]
19 Feb 2013 by Simon_Whale
here is how to do it in SQL Server& (Bitwise AND) (Transact-SQL)[^]
5 Mar 2013 by Alamgirable
Is it possible to write your own operators in c++ like and "AND" "OR" "NOT".
21 Apr 2013 by vijay__p
Try below code Delete
22 Oct 2013 by Skippums
I have a situation that makes me think that "operator =" is not being inherited, but perhaps I fail to understand the standard. Here is a minimal example that illustrates the problem:struct Foo { Foo &operator =(double const val);};struct Bar : public Foo { };int main(int...
28 Nov 2013 by radals
i did it but i want this link pass parameters to another page with 2 valuesto be as this :
19 Jan 2015 by PIEBALDconsult
I don't think you want the & in printf("no of brick = %i", &ht); and the other lines.
22 May 2015 by forest-321
Hi,all.I have made = operator and use in VC++.The definition is as follows:class CMain{public: CMain(int nDim) { dim = nDim; pK = new int[nDim]; memset(pK, 0, sizeof(int) * nDim); } ~CMain() { if(pK != NULL) { delete[] pK; pK =...
14 Nov 2015 by MaxySpark
How can I overload > bitwise operator in c++?
6 Feb 2016 by Member 12147362
hello. I have the task to overload operator + between a char* and an integer like this:char* operator+(const int k, char* c){ for (int i = 0; i> c;// abc c = c + 2; cout
23 Jun 2016 by super_user
i try this webmethod . HERE vname is varcharWhat I have tried:[WebMethod]public static string GetVo(string fdate, string tdate, string region){string data2 = "[";try{T1 DB = new T1();var rea = (from rv in DB.tblRVjoin Reg in DB.tblR on rv.RegionID equals...
19 Aug 2016 by EpicKai
import java.lang.Math;public class Solution { public int divide(int dividend, int divisor) { int count = 0; boolean isNegative = false; if(dividend == divisor){ return 1; } else if(divisor == 1){ return dividend; }...
19 Aug 2016 by OriginalGriff
I take it this is your homework, hence the restrictions? :laugh:There are several faster algorithms than repeated subtraction: Division algorithm - Wikipedia, the free encyclopedia[^]I prefer binary division, as it fits computers very nicely: Binary Division[^]You should have been able...
15 Sep 2016 by Arul Prasath Kolandasamy
Can anyone help me to write a code for "template operator overloading without class for complex number addition and multiplication"the main theme is i should not use "class" and i can use structure and i should use "template" to add and multiply for two complex number, i tried to search in...
15 Sep 2016 by CPallini
Why do you need templates for such a task?Could you please show us your 'not working code'?Here an example of global (without class) operator overloading: How to overload opAssign operator globally in C++ - Stack Overflow[^].[update]I give you an example#include using...
18 Feb 2018 by OriginalGriff
When you posted this question this morning: C# how to compare two triangles with operator >[^] you were told what was wrong with your whole approach. The problems haven't changed; and neither has your code...
29 Jul 2018 by Kornfeld Eliyahu Peter
It has nothing to do with Vs 2017... '
28 May 2020 by Doctor GME
this is my calculator design: https://www3.0zz0.com/2020/05/28/19/797035332.jpg[^] the upper textbox is for calculation while the lower is for result it is very simple for me to write a calculator which can do simple process like: 1 + 1 or 2 -1...
19 Sep 2020 by Patrice T
Comments in code is a good habit, continue. Quote: 0x3048 = 0111 0000 0100 1000 Since 0x3048 is 0011 0000 0100 1000 and 0111 0000 0100 1000 is 0x7048 your example is rather confuse. Rewrite what you want to do with following notation: Take a...
19 Sep 2020 by KarstenK
Your code is confusing by using offsets and not starting with zero as first index. I think you have a bug in your code. In the case of perfomance problems: I would use some constants or macros and avoid an (expensive) function calls. tip: Write...
22 May 2023 by Coral Kashri
Fold-expressions in extreme cases
8 Sep 2016 by Thomas Daniels
This article explains how bitwise operators work and this article explains also several purposes of them with examples in C# and VB.NET.
4 Feb 2014 by Yvan Rodrigues
Maybe writing a tip will mean the last time I fall for this.
31 Oct 2013 by Lee Reid
How to create 'generic' classes and methods which use operators such as +,-, / and *
22 May 2015 by CPallini
You didn't (re-)define the assignment operator for your class (your code doesn't even compile). You have to (re-)define both the assignment operator and the copy constructor in order to avoid catastrophic failures, e.g.CMain (const CMain & other) // copy ctor{ clone(other);}CMain &...
22 Oct 2015 by yash soman
The tip is about using Elvis operator which is introduced in C# 6.0 for Null Reference Checks. It gives an example of how to use it.
1 Feb 2017 by Jochen Arndt
Your implementation of the postfix operator is wrong. You must return temp (the unchanged object) instead of the modified object:Time operator++(int){ Time temp(hours, minutes); minutes++; if (minutes >= 60) { hours++; minutes = minutes - 60; } ...
18 Feb 2013 by Deenuji
I have sql table like below....Id Bag Tapee Band shoes knife guitar watch umbrella hammer1 1 0 1 1 0 1 1 1 02 0 0 1 1 0 1 1 0 03 0 0 1 1 0 0 0 0 0 i wanna do AND Operation using transcation id....For example i do AND Operation for transcation id 1 and 2 means we can get...
19 Sep 2020 by Member 14942281
I am looking to implement the prototype for read_and_write, but couldn't get it right. Any help is appreciated. I am able to extract bits. In this below code for write_val1, my intent is to write only the first 9 bits of final_val into...
26 Apr 2013 by Manfred Rudolf Bihy
This has to do with how Python stores strings internally. Two string literals that have the same content are stored as the same string instance1. Since strings are immutable this is OK to do so. The first sample uses strings so both the strings created from the same string literals are both...
13 Dec 2018 by Rahul Raj Infosys
code part1: name1="rahul" name2="rahul"code part2:name1=[1,2,3]name2=[1,2,3]If I run the following code:print name1 is name2I get "True" for code part1andI get "False" for code part2why? why the "reference" is same for name1 and name2 in...
14 Oct 2013 by unscathed18
As an example, consider the following code:class Rational{private: int a; int b;public: Rational(); // Definition doesn't matter as for now/* Here's the deal: */ Rational operator*(Rational& rhs); //The same as below but differs in returned value type ...
22 May 2015 by H_
Firstly you have to forget the C-prefix - its ugly and its not part of the ungary notation how the most of people think.Now to your problem. You only make a shallow copy here: pTemp[i] = m; like memcpy. So when m gets out of scope the destructor of CMain gets called. The destructor now...
19 Feb 2013 by Shanalal Kasim
Hi,Try below sql select min(bag),min(Tapee),min(Band),min(shoes),min(knife),min(guitar),min(watch),min(umbrella),min(hammer) from [dbo].[transcation] where id in(1,2)Answer is0 0 1 1 0 1 1 0 0
14 Oct 2013 by KarstenK
the central consideration is to avoid overhead in constructing and copying data.So the best practice is to use constant reference values for that, to also avoid bugs in manipulating the operands.Rational& operator*(const Rational& rhs) const;//return a reference to a new object
1 Feb 2017 by Member 12975649
#include using namespace std;class Time {private: int hours; // 0 to 23 int minutes; // 0 to 59public: // required constructors Time(){ hours = 0; minutes = 0; } Time(int h, int m){ hours = h; minutes = m; } // method to...
31 Jan 2017 by Richard MacCutchan
Since you are overriding both operators the normal ordering rules do not apply. The right-hand side of each expression will be completely evaluated before the result is passed to the left-hand side. Stepping through the code with your debugger will show you what happens.
29 Jul 2018 by Member NFOC
I already made a function but just not printing and giving the error with compatability of the
29 Nov 2013 by C@dER@j
Make your question more specific.
19 Feb 2013 by K C Behera
use bellow SQL Syntaxselect * from ranscation where ranscationid between 1 and 2
19 Feb 2013 by lee gee
try to read this one.i hope you can get an idea of this.http://msdn.microsoft.com/en-us/library/aa276873(v=sql.80).aspx[^]
21 Apr 2013 by ajaykalarickal
Hello,i'm developing a small website n now i'm facing a problem. I designed my Sql table so that when ever I'm signed in, i set one of my field as "1" and when i log out, it changes to "0". So, I want to set some of the control's visibility so that some should be visible only when I'm signed...
12 Jul 2013 by A Fellow Coder
Hello. What exactly is the lambdas operator, and how should I define it in my head? For example:x = y; //x is the same number as y.if (x != y) //if x and y are different numbers do this, this, and this.{//this, this, and this}//How should I read this?if...
3 Feb 2014 by CAS1224
I'm hoping to find a way to prevent symbols in my vb.net windows forms application using a datagridview with the Char.IsSymbol() method, however I'm hoping to still allow the user to input mathmatical operators into the datagridview. Is there a way to prevent all symbols except mathmatical...
19 Jan 2015 by Member 11386522
Hey there, I just started my first program in years and i have a problem. Basically I started writing a construction estimation app. i enter 1 for ht and len but it keeps showing both as "229332". Here is the code:#includeint no_brick = 0, no_block, no_hours, bl_price =...
22 May 2015 by Ralf Meier
I'm not complete sure ... have you tried := instead of =
14 Aug 2020 by lelouch_vi 2
Hello, everyone, I know this question of mine is very noob for you guys but I can't just sleep not knowing the meaning of this symbol in java : Im searching how to convert a string arraylist to an integer arraylist and I saw this: for (String...