+ 1
can the case in switch condition be negative??eg case: -1..
2 Réponses
+ 1
the type of the expression inside case should be implicitly convertible to the same type as the result of the expression of the switch block.
The code
-------
extern class Person; // Externally defined class.
...
Person *person1, *person2, person3;
...
switch(person3) {
case *person1:
// person3 is equivalent to person1
case *person2:
// person3 is equivalent to person2
}
-------
is perfectly valid. But you should define the equality operator and copy/move contructors to make what you want when comparing two Person instances.
+ 1
yes
code is like-
#include <iostream>
using namespace std;
int main()
{
int i=(-20);
switch (i)
{
case 2:
cout<<"not equal";
break;
case (-20):
cout<<"equal";
break;
default:
cout<<"useless";
}
return 0;
}
//output- equal