Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

noob question c++

Name: Anonymous 2009-07-12 13:15

Why doesn't this work?

#include <iostream>
using namespace std;
int main(int argc,char** argv){
   string name;
   cout<<"What is your name?"<<endl;
   cin>>name;
   if(name=="Anonymous")
   cout<<"Aw don't be shy..."<<endl;
   else
   cout<<"Hello "<<name<<"!"<<endl
   return 0;
}

Name: 17 2009-07-12 21:50

>>20
But just because it's "more common" doesn't mean you can just get rid of reference equality
Learn to read. I didn't suggest getting rid of reference equality, I suggested replacing it with the magic instance variable.

I agree that == should be a value comparison for immutable types (afaik C# sort of works this way?), except that now you have to know the details of a type before you can figure out whether == will do a value or reference comparison.
Which is just one reason my way is better.

The real fix for this imho is that == in Java should always generate a compiler error for immutable types. (...) and you are prevented from doing a reference comparison on types for which the result is undefined.
Great. So now programmers are forced to write comprehensive .equals() methods (or, god forbid, .hashCode()) just to be able to determine whether two differing mutable objects are the same objects, and they have no way of knowing whether two identical ones are different at all?
That's really going to improve that clusterfuck of a language.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List