Question about equity tests?

This is a discussion on Question about equity tests? within the C++ Programming forums, part of the General Programming Boards category; Ok, I've encountered my compiler telling me I possible inproporely assinged testing for equity. I know that '==' is the ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Question about equity tests?

    Ok, I've encountered my compiler telling me I possible inproporely assinged testing for equity. I know that '==' is the usual thing to test for equity.

    But, what does this do then?
    Code:
    if(1 = 2)
     cout << "???... How?";
    The expression
    Code:
    1=2;
    That isint valid is it? But then why is if(1=2)? Or is this doing something else rather than assinging 1's value 2?

    Thank you!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    Well I know that if they were both variables, it would assign the data from the variable on the right into the variable on the left. But with 2 numbers I am not sure.

    It might temporarily change the value of 1 to 2, but the next time you do anything with the number it will be 1 still.

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Ah I see. But does that cause this to be true?

    Code:
    if(1=2)
     cout << 1+1; //result is 4?
    cout << 1+1 //Result 2 because its outside the if?
    Or does it only effect the red part?
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    I was just going to test it to see exactley what happens, and the compiler wont even let you. I think it is because it is a static value, a value that can't be changed. Kind of like trying to put a variables data into a string literal by doing the following.

    char* MyVar = "Bye";
    "Hello" = MyVar;


    Have a little look into lvalues and rvalues
    http://cplus.about.com/od/cprogrammi...def_rvalue.htm
    Last edited by John_; 01-26-2006 at 01:58 AM.

  5. #5
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Hmm, I guess not.

    Well, thanks for your help!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21