- Dev C++ No Match For Operator
- C++ No Match For Operator
- Dev C++ No Match For Operator
- C++ No Match For ‘operator ’
The 'not' operator is a little different to 'and' and 'or'. It can only be prefixed to single expressions and essentially just inverts the boolean value of an expression. If the value is true, 'not' will flick it to false - the 'not' operator is expressed via an exclamation mark, and hence!true is false, and!false is true. C: Mathematical Operators Operators are simply symbols that perform a certain function - some of these perform mathematical functions. In this tutorial, we're going to build on your knowledge of user input, outputting data, and variables, to learn about some of the basic mathematical operators. No match for 'operator=' in 'input =. That means that the compiler can't find a rule, that can allow you to assign the input to something in the right side. So, now, when we've already know that the problem is in the assigning value, the debugging proccess is much simpler - we have to find what type of value does the sort method returns, we.
Good afternoon Daniweb, I have a simple (and probably idiotic) problem today, I have a simplistic program that simulates a Train station, trains come in, they go into a stationDock and come out after a while.
The stationDocks are an array of trains, either pointing to a train or being NULL (at least that's what it should be, I probly did an error somewhere in the implementation)
The stationDocks are an array of trains, either pointing to a train or being NULL (at least that's what it should be, I probly did an error somewhere in the implementation)
![Dev c++ no match for operator Dev c++ no match for operator](/uploads/1/2/6/1/126160652/167043057.jpg)
WideVar.cpp: In static member function ‘static void wideVar::freeDock(int)’:
WideVar.cpp:67: error: no match for ‘operator=’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) = 0’
Train.h:7: note: candidates are: Train& Train::operator=(const Train&)
WideVar.cpp: In static member function ‘static bool wideVar::dockIsEmpty(int)’:
WideVar.cpp:69: error: no match for ‘operator’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) 0’
WideVar.cpp: In static member function ‘static void wideVar::setDock(int, Train*)’:
WideVar.cpp:71: error: no match for ‘operator=’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) = train’
Train.h:7: note: candidates are: Train& Train::operator=(const Train&)
WideVar.cpp: In static member function ‘static int wideVar::compareDock(int, Train*)’:
WideVar.cpp:73: error: base operand of ‘->’ has non-pointer type ‘Train’
WideVar.cpp:73: error: expected `}' at end of input
WideVar.cpp:67: error: no match for ‘operator=’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) = 0’
Train.h:7: note: candidates are: Train& Train::operator=(const Train&)
WideVar.cpp: In static member function ‘static bool wideVar::dockIsEmpty(int)’:
WideVar.cpp:69: error: no match for ‘operator’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) 0’
WideVar.cpp: In static member function ‘static void wideVar::setDock(int, Train*)’:
WideVar.cpp:71: error: no match for ‘operator=’ in ‘*(((Train*)(((unsigned int)i) * 36u)) + wideVar::stationDocks) = train’
Train.h:7: note: candidates are: Train& Train::operator=(const Train&)
WideVar.cpp: In static member function ‘static int wideVar::compareDock(int, Train*)’:
WideVar.cpp:73: error: base operand of ‘->’ has non-pointer type ‘Train’
WideVar.cpp:73: error: expected `}' at end of input
P.S. I commented out (only in the example) the parts of the code unrelated to the problem.
Dev C++ No Match For Operator
Thank you very much for your help!
- 2 Contributors
- forum 2 Replies
- 1,819 Views
- 13 Hours Discussion Span
- commentLatest Postby jonyb222Latest Post
C++ No Match For Operator
vmanes1,165
You're trying to assign NULL to a Train object, or to compare NULL to a Train object. You haven't overloaded the = and operators, and it wouldn't make sense to assign or compare NULL in any case.
ar is the pointer - that can be assigned or compared to NULL. But assigning NULL will orphan your entire array of Train objects.
If your goal is to show that an element of the ar array is available, you might add a marker to the Train objects (valid or invalid).
If you want to be able to actually delete a Train object, consider making ar a pointer to pointers.
Operators are simply symbols that perform a certain function - some of these perform mathematical functions. In this tutorial, we're going to build on your knowledge of user input, outputting data, and variables, to learn about some of the basic mathematical operators.
C++, like most programming languages, works on the concept of 'expressions' - combinations of symbols which represent values. If a simple mathematical statement is written, for example
5+5
, the calculation will be evaluated by the C++ compiler, and the result put in the place of the expression - in this case, 10. The +
operator which is used to add two number values, be these constants (or literals) like '5', or variables of supported types (e.g. int
, double
, or float
), can be shown to behave in this way with a simple cout
. Take the following in which '14' is outputted instead of the actual text '8+6':The use of operators is often dependent on the to the string. Take for example the following:
Note that in the above that the 'expression' type functionality is extremely important. The expression,
one + ' Bob!'
is being evaluated to 'Hello Bob!'
and then outputted, however the variable 'one' is not being changed. If we wanted to actually change the value of the variable 'one' we would have to set it using something like the equals operator:There is also another mathematical operator related to
+
which can do the 'one = one +' functionality for us - this is the +=
operator. So instead of typing something like the above, we could instead use something a little bit cleaner like:The four basic mathematical operators, as you may expect, are those of addition, subtraction, multiplication, and division. These are represented by the
+
, -
, *
and /
operators as appropriate. Each of these also has a +=
equivalent for setting variables to themselves, add, subtracted, multiplied by, or divided by, some other value - these are +=
, -=
, *=
, and /=
as appropriate. There is also another mathematical operator which we're going to cover in this tutorial, which is called the modulus operator. This does division of whole numbers and gives the remainder of that division - for example 5 % 3
will be '2' as 3 goes into 5 once, with 2 remaining. This task may seem quite niche at first, however can become quite useful in a number of tasks.All of these operators can be used with either variables or literals of the correct type (in this case, you'll want to use those of a 'number' type), and perhaps the easiest way to show the functionality of these operators is to simply give an example of some expressions using them,
cout
ing the results:So looking at the above, do they all output as expected? The majority do, however the
7 / 2
calculation outputs 'incorrectly' as '3'. This is because our application knows it's dealing with whole number division (as we've specified integer literals), and so it rounds the result to a whole number. To solve this problem if this functionality is not what we want, as is the case here, we can simply change the literals to those of the double
type by changing the calculation to 7.0 / 2.0
. This change means that the calculation outputs as we would expect.So now that we know how to use basic mathematical operators in C++, let's put this to some use! Before we create a 'big' application demonstrating a number of the operators we've covered - I just want to give a moment for the modulus operator, who I feel may be under-appreciated at this point. A great use for it is checking if a whole number is even or not -- if the number divides by 2 with no remainders, i.e.
number % 2 is equal to 0
the number must be even, otherwise it must be odd. We don't know how to check conditions like this quite yet, but come back to this after going through the next tutorial if you have some extra time, and try to create a basic program which takes input into an integer variable and then outputs if the number entered is even or not.So back to creating an application with some practical use! I thought it might be a nice idea to create a program which uses the famous Pythagorean Theorem to calculate the longest side of a right-angled triangle given the other two sides. If you are unfamiliar with the equation, it states that the square of the longest side of a right-angled triangle is equal to the added squares of the other two sides. So if the longest side is 'c' and the other two are 'a' and 'b', the equation would be:
a2 + b2 = c2
Dev C++ No Match For Operator
So let's first get our application set up! Let's just think about includes for a second - we're definitely going to need
iostream
for outputting data and getting data from the user, but we're also going to need to somehow get the square root of a variable or expression to calculate the length of the longest side of the triangle. This functionality, along with some other advanced mathematical stuff, is stored inside the cmath
header file, and so we should include this in our code too.C++ No Match For ‘operator ’
Note that with
cmath
included, we can square root things using the sqrt
function. You can do what is called 'calling' a function by specifying the function name, followed by whatever you need to give the function to do it's job in brackets. If you don't need to give the function any values, you can just give empty brackets - ()
. In our case, we want to call the sqrt
function with the value of the square of 'a' plus the square of 'b', and this expression will evaluate into the value we're looking for - the length of the longest side. Before this however, let's just use our knowledge of cin
and cout
to prompt the user for the first two sides (which, since they may be decimals, should probably be of type double
):As talked about previously, we can now simply make use of the
sqrt
function to square root the added squares of these values. Squaring something is just multiplying it by itself, and thus we want the sqrt
of a*a + b*b
- hence sqrt(a*a + b*b);
. Once again the 'expression' type functionality comes in handy as the simpler mathematics is first evaluated to give the result, and then this is passed to the sqrt
function and square rooted to give us the result. Some people may prefer using another variable to deal with the result and get rid of some of the nested calculations in brackets - but I don't think such clutter is necessary here. The full code for our application can be seen below: