C++ 106 For loops and Dynamic Arrays
Uploader Comments (ryutenchi)
All Comments (20)
-
@ryutenchi wow, this was quite some time ago. I passed my C++ course, lol. Thanks!
-
what happened to the delete part with out it its gonna give massive excpetion
-
You know, from a coding perspective this is really tedious to go through the entire dynamic array process every time one is needed- why not just add a library/function for it?
-
@t3hdewd Use vecotrs or just malloc away.
-
hi.... where did you download ur type of C++ programming from?
i have a 64 bit computer and it wont let me run a c++ program..it says it only runs in 32 bit computerss :(
-
Sorry, Didnt mean to make my last comment sound that way. i just re-read it.
What i mean is the other video sticks on topic, and doesnt cloud the new guy with additional information such as a FOR loop.
it actually TEACHES dynamic memory, as an advanced topic expecting basic class/loop knowledge already "as probably should when covering a more advanced topic like dynamic memory use"
-
Yes, I figured out that in the start, but I had some mistake and I though there is another way, but it seems I was right Thanks ;-)
So how do we resize dynamic arrays, keeping the old values?
t3hdewd 2 years ago
you have to use a temp. pointer then you can set the array to a new Whatever[newsize]; and copy the values over from the temp point. I know it's a bit complex but there is no build-in method so that's the best way to do it with this method. Alternatively, you can use the *allac C commands to create/size/resize a pointer and then delete them with the free command.
ryutenchi 2 years ago
i hope u understand my question here it goes:
I set an array for example:
int number[1]; the i set number[0]=100, number[1]=200.
Is there any way to change number[0] to different number while running the program?
if so let me know
thx
btorrres18 3 years ago
First, "int number[1];" will only have 1 "slot" in it, so "number[1]=200;" will through an error.
Second, it is only number of items in an array that you can not change(and that's not always true, but is out of scope). You can change the values at any point so
number[0]=100;
if(blue) number[0] = 42;
else number[0] = 73;
is perfectly valid. hope that helps.
ryutenchi 3 years ago
Under tutorial about polimorphism I asked in comment about pointers and what made me confused was that "new" word. So:
character* me; // pointer to an adress in memory
me = new Player();
Last line makes compiler to look at the constructor "Player()" of the "character" class and then write a NEW set of arguments stored in this constructor into the memory at the adress pointed by "me".
You've created an instance of the "character" class but straight into the memory at the "me" adress :).
cgofme 3 years ago
Not quiet.The character class pointer"me"is set up as a generic character pointer that can be used to access any of the public functions or variables of a character,but since we then make an instance of Player and set it equal to it, it now is actually a player,but we only have access to the functions and variables that were inherited or redefined from the base class(character).So polymorphism lets me make a base class pointer and then point it at an object of a derived class at anytime.
ryutenchi 3 years ago