understanding classes...

  • Topic Archived
You're browsing the GameFAQs Message Boards as a guest. Sign Up for free (or Log In if you already have an account) to be able to post messages, change how messages are displayed, and view media in posts.
  1. Boards
  2. Game Design and Programming
  3. understanding classes...

User Info: Cheezmeister

Cheezmeister
1 year ago#11
bool contains_the_letter_q(string s)
{
for (int i = 0; i < s.length(); ++i)
{
if (s[i] == 'q') return true;
}
return false;
}

contains_the_letter_q("Shamiqua"); // true



Here the function has a local variable i. The calling code can't see it or modify it. Why is this useful? Because it doesn't care that contains_the_letter_q looks at letters in order. It doesn't give a crap. It just wants to know that there's a 'q' in there somewhere. Also, if it has its own local i variable, it won't clash.

Private parts on classes are sort of similar, except that you have to be more explicit about them.
I make games!
http://luchenlabs.com

User Info: Sinroth

Sinroth
1 year ago#12
Cheezmeister posted...
bool contains_the_letter_q(string s)
{
for (int i = 0; i < s.length(); ++i)
{
if (s[i] == 'q') return true;
}
return false;
}

contains_the_letter_q("Shamiqua"); // true



Here the function has a local variable i. The calling code can't see it or modify it. Why is this useful? Because it doesn't care that contains_the_letter_q looks at letters in order. It doesn't give a crap. It just wants to know that there's a 'q' in there somewhere. Also, if it has its own local i variable, it won't clash.

Private parts on classes are sort of similar, except that you have to be more explicit about them.


That's actually a really nice analogy. I might use that when I'm next tutoring intro comp sci.
I live in a big house and it's handy to have a pair of running shoes so that it doesn't take me forever to get from one area of the house to another.

User Info: flussence

flussence
1 year ago#13
...I wish this site's own code tags weren't completely worthless. We don't use 800x600 any more, would it kill them to put some white-space: pre-wrap in there and stop acting like a horizontal scrollbar is some kind of unspeakable 9/11-tier horror?
https://gitlab.com/flussence/GFCSS ~~ Make GameFAQs load 50% faster

User Info: scar the 1

scar the 1
1 year ago#14
flussence posted...
...I wish this site's own code tags weren't completely worthless. We don't use 800x600 any more, would it kill them to put some white-space: pre-wrap in there and stop acting like a horizontal scrollbar is some kind of unspeakable 9/11-tier horror?

The technology just isn't there yet :^)
Everything has an end, except for the sausage. It has two.

User Info: woody71

woody71
1 year ago#15
Thanks I think I understand the idea behind them<3
<Random quote of game I'm playing>
  1. Boards
  2. Game Design and Programming
  3. understanding classes...

Report Message

Terms of Use Violations:

Etiquette Issues:

Notes (optional; required for "Other"):
Add user to Ignore List after reporting

Topic Sticky

You are not allowed to request a sticky.

  • Topic Archived