Page 1 of 1

Regards

Posted: Mon Jun 29, 2009 7:48 pm
by zodiac976
I would like to thank everyone for helping me understand
scopes of classes, pointers and dynamic objects. I am
actually using pointers now in my code :mrgreen: and
this:

Example: Character * ptrChar = new Character(); //parameters if I need them

Really comes in handy and also "this pointer" to 8-).

Re: Regards

Posted: Mon Jun 29, 2009 7:59 pm
by davidthefat
zodiac976 wrote:I would like to thank everyone for helping me understand
scopes of classes, pointers and dynamic objects. I am
actually using pointers now in my code :mrgreen: and
this:

Example: Character * ptrChar = new Character(); //parameters if I need them

Really comes in handy and also "this pointer" to 8-).
I really need to get onto pointers, I kinda get it but not really... Its like you did Algebra, now go onto Algebra 2

Re: Regards

Posted: Mon Jun 29, 2009 8:07 pm
by zodiac976
I got a little worried about not using pointers in my new project
but I went back today and plugged in pointers where they are
needed and not only does the program run good it looks great
and is more toward OOP :mrgreen:.

I could go on with a huge list of what I learned so far but I can
say I learned a lot more here than I did in college classes.

I can't wait to finish my text-based RPG and show it off ;).

Re: Regards

Posted: Tue Jul 07, 2009 5:55 pm
by Ginto8
Character*? I'm hoping you don't mean a substitution for char, because dynamic arrays of chars are about the most useful things in C++. example of a possible use for them (a static array would probably be more appropriate for certain parts):

Code: Select all

char* myCStyleStr = calloc((strlen("Hello World!") + 1) * sizeof(char));
strcpy(myCStyleStr, "Hello World!");
printf("%s\n", myCStyleStr);
myCStyleStr = realloc(myCStyleStr, strlen("Hello World! and Mars too!") + 1);
strcpy(myCStyleStr + strlen("Hello World!") + 1, " and Mars too!");
printf("%s\n", myCStyleStr);
free(myCStyleStr);
getchar();
stick that in main() and you'll get the output:

Code: Select all

Hello World!
Hello World! and Mars too!
so char arrays (especially dynamic) are extremely useful, and I'm hoping you didn't make a class to substitute them, because that's just clunky and wasteful :x .
</rant>

Re: Regards

Posted: Wed Jul 08, 2009 12:44 am
by zodiac976
Ginto8 wrote:Character*? I'm hoping you don't mean a substitution for char, because dynamic arrays of chars are about the most useful things in C++. example of a possible use for them (a static array would probably be more appropriate for certain parts):

Code: Select all

char* myCStyleStr = calloc((strlen("Hello World!") + 1) * sizeof(char));
strcpy(myCStyleStr, "Hello World!");
printf("%s\n", myCStyleStr);
myCStyleStr = realloc(myCStyleStr, strlen("Hello World! and Mars too!") + 1);
strcpy(myCStyleStr + strlen("Hello World!") + 1, " and Mars too!");
printf("%s\n", myCStyleStr);
free(myCStyleStr);
getchar();
stick that in main() and you'll get the output:

Code: Select all

Hello World!
Hello World! and Mars too!
so char arrays (especially dynamic) are extremely useful, and I'm hoping you didn't make a class to substitute them, because that's just clunky and wasteful :x .
</rant>
no Character is an object of a class not the data type char.
I hardly use c-strings as I always fall back on the string
object.