• Lucid Dreaming - Dream Views




    Results 1 to 25 of 165

    Hybrid View

    1. #1
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Actually I have a question...

      I'm learning C++ and right now I'm reading about ++ and --

      The example it gives me is this...

      Example 1:
      Code:
      B=3;
      A=++B;
      // A contains 4, B contains 4
      Example 2:
      Code:
      B=3;
      A=B++;
      // A contains 3, B contains 4
      I don't really understand the whole ++ and -- and how it affects the A and B variables. Can someone explain how it adds up?

      Edit: Also, how does all this make up a video game engine?
      Last edited by slayer; 01-08-2010 at 01:41 AM.

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      increment and decrement
      (Ie. add one, or subtract one)
      used all the time when looping and keeping count of things

      a++ means "return the value of a, and then increment it"
      ++a means "increment a, then return the value"

      subtle (but important) differences, however the differences between the pre & post incrementation are only important if you care about the value of a variable mid-operation

      Code:
      for (i = 0; i < max; i++)
      {
      
      }
      and
      Code:
      for (i = 0; i < max; ++i)
      {
      
      }
      are identical in operation
      (because we do not care about the value of 'i' mid-operation

      however,
      say we are keeping a count of something that we later need to step back through in reverse

      Code:
      void increment_something(int var)
      {
          old_var = var++;
      }
      here, we do care about the value of var mid-operation, therefore we store the "old value" of var and increment var

      You can of course do this
      Code:
      void increment_something(int var)
      {
          old_var = var;
          var++;
      }
      then we've split the operation into two
      and now we no longer care about the return value of the increment
      (\_ _/)
      (='.'=)
      (")_(")

    3. #3
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Ynot View Post
      Code:
      for (i = 0; i < max; i++)
      {
      
      }
      and
      Code:
      for (i = 0; i < max; ++i)
      {
      
      }
      are identical in operation
      (because we do not care about the value of 'i' mid-operation
      Almost correct. In for loops you want to do the latter because in order to return, then increment, it has to keep a copy of it. Not a problem with ints, but with objects it can.

      ++ and -- are weird to learn.

      b = ++a; is like this:
      a = a + 1;
      b = a;

      b = a++; is like this:
      b = a;
      a = a + 1;


    4. #4
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Err...you're using some things in there I haven't learned yet. So I think you just made it more confusing for me...

      Edit: Ok that makes it a little easier to understand...

      So would it be something like this for the 2nd part?

      b = 1;
      b = a++;

      Would the result be: b = 1, a = 2? Because I already defined b to equal 1 and then a equals b which is 1, then I add a to a to get 2, right?
      Last edited by slayer; 01-08-2010 at 02:08 AM.

    5. #5
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      follow a tutorial on C++
      I've always liked this one
      http://www.cprogramming.com/tutorial/lesson1.html

      It'll take you through the basics, and slowly build up to more complex things

      *edit*
      Just realised you're not the OP.....
      (\_ _/)
      (='.'=)
      (")_(")

    6. #6
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Lol no I'm not

      But I'll make good use of this thread...

      Also, I'm following this tutorial so far: http://cplusplus.com/doc/tutorial/operators/

      edit: but again, how does all this make up a video game engine? Or any program?

    7. #7
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Well, we break it up. We break down the seemingly huge task of a full program and break it down into pieces which are more manageable. We then code each part, sometimes sticking the together in one executable, but more commonly, we create a complex set of dynamic libraries.

      A video game engine would probably be about a quarter of a million lines of C++ code, broken up into maybe 1000 different files.

    8. #8
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Wow...quarter of a million...

      Well I guess that adds up fast seeing how small lines of code are.

      A Roxxor wants me to make a simple text based game. I'm not sure how I'm going to do this...

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •