7

Possible Duplicate:
Why switch statement cannot be applied on strings?

In some post I read that the reason is "the compiler must understand what it means for two values to be equal", but in C# it also doesn't know and just call function similar to Equals, so why C++ cannot do it either?

Community
  • 1
  • 1
theateist
  • 13,879
  • 17
  • 69
  • 109
  • 1
    `C++` also doesn't have a garbage collector while `C#` does. – John Dvorak Dec 20 '12 at 08:51
  • 3
    [All features are unimplemented by default](http://coding.abel.nu/2012/02/features-are-unimplemented-by-default/). – SWeko Dec 20 '12 at 08:52
  • 2
    C++11 DOES support switch cases with Strings. – 1615903 Dec 20 '12 at 08:52
  • 2
    @user1615903: Not it doesn't. "The condition shall be of integral type, enumeration type, or of a class type for which a single non-explicit conversion function to integral or enumeration type exists" – Mike Seymour Dec 20 '12 at 08:53
  • @MikeSeymour: call it what you want, I still think this is a switch case with strings: http://siliconkiwi.blogspot.fi/2012/04/c11-string-switch.html – 1615903 Dec 20 '12 at 08:54
  • take a look here: [Switch on Strings in C++](http://www.codeguru.com/cpp/cpp/cpp_mfc/article.php/c4067/Switch-on-Strings-in-C.htm) – Pascal Qyy Dec 20 '12 at 08:55
  • 1
    @user1615903: That's not switching on a string, it's switching on a non-unique value calculated from a string. You still need to compare the strings to avoid false positives from hash collisions. – Mike Seymour Dec 20 '12 at 08:57
  • @MikeSeymour ... or play the loterry. – John Dvorak Dec 20 '12 at 08:59
  • Dear administrators, I read the post you placed in my post before posting this post. The quote I used is from that post and that's why I asked why C++ cannot use the same as C# - calling something like `Equals` method – theateist Dec 20 '12 at 09:12

0 Answers0