[Solved] ambiguous overload C++ for operator = [closed]


 if (dungeonLevel = "1")

This is the line causing the error. You want it to be:

 if (dungeonLevel == 1)

There are 2 changes I have made here:

Firstly, I replaced the = sign, called the assignment operator, with the == sign, which is the comparison operator. The assignment operator is used when you assign the variable on the left of the operator the value (could be a fixed value like 5, “hello”, etc…). It does not make comparisons, as you are trying to do in your if-statement condition. Therefore, you need to use the comparison operator (==), which checks whether the statement on the left is the same as the statement on the right and passes on a Boolean value (true or false), depending on the results of the comparison, to tell the compiler whether to enter the if-statement’s body or not. Therefore, you need to use the (==), not the (=) in your if-statement condition.

Secondly, I removed the apostrophes from the 1 in your if-statement condition, as you want an int value there, not string. When you run through a loop, you increment a counter, which has to be an int value.


Another thing:

for (dungeonLevel = 0; dungeonLevel < 5; dungeonLevel++)

In this line, you have not declared the data type of dungeonLevel (maybe you did this outside of the for-loop). It should be declared as type int.

Change your for-loop header to this:

for (int dungeonLevel = 0; dungeonLevel < 5; dungeonLevel++) // Notice that I added the data type of dungeonlevel in its initialization statement

6

solved ambiguous overload C++ for operator = [closed]