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 and
this:
Example: Character * ptrChar = new Character(); //parameters if I need them
Really comes in handy and also "this pointer" to .
Regards
Moderator: Coders of Rage
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: Regards
I really need to get onto pointers, I kinda get it but not really... Its like you did Algebra, now go onto Algebra 2zodiac976 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 and
this:
Example: Character * ptrChar = new Character(); //parameters if I need them
Really comes in handy and also "this pointer" to .
- zodiac976
- Chaos Rift Regular
- Posts: 156
- Joined: Thu Jun 18, 2009 10:03 am
- Current Project: Booklet & Text RPG
- Favorite Gaming Platforms: PC, PS3, PSP
- Programming Language of Choice: C++
- Location: AL
- Contact:
Re: Regards
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 .
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 .
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 .
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 .
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Regards
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):
stick that in main() and you'll get the output:
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 .
</rant>
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();
Code: Select all
Hello World!
Hello World! and Mars too!
</rant>
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- zodiac976
- Chaos Rift Regular
- Posts: 156
- Joined: Thu Jun 18, 2009 10:03 am
- Current Project: Booklet & Text RPG
- Favorite Gaming Platforms: PC, PS3, PSP
- Programming Language of Choice: C++
- Location: AL
- Contact:
Re: Regards
no Character is an object of a class not the data type char.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):stick that in main() and you'll get the output: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();
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 .Code: Select all
Hello World! Hello World! and Mars too!
</rant>
I hardly use c-strings as I always fall back on the string
object.