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?
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"
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.
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
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 :).
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.
no, if you notice I typed that inital 4 faster then it output the second line to the screen, so if you pause it and look at the beginning of the line you'll see that 4. the cin looks at your input upto the [Enter] so even if you type before it gets all the text to the screen that "4" or whatever is already in the input buffer and then when you press [Enter] it flushes that buffer to that variable.
what happened to the delete part with out it its gonna give massive excpetion
MrInayat619 9 months ago
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?
FlamingPope 1 year ago
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 :(
4166865459 2 years ago
This has been flagged as spam show
@4166865459 Let me explain this to you.
"where did you download ur type of C++ programming from?"
C++ is a language, you cant download it as a whole.
"i have a 64 bit computer and it wont let me run a c++ program..it says it only runs in 32 bit computerss :( "
Yo umean you have a 64Bit OS and a 64 bit capable CPU!Any modern C++ compiler will compile happily on a 64bit os.
0121ryanh117 2 years ago
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"
samljer 2 years ago
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
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 ;-)
t3hdewd 2 years ago
@t3hdewd Use vecotrs or just malloc away.
0121ryanh117 2 years ago
how to make a 2d dynamic array of string data type ? i have an assignment of it i dont know howto make it? any help will be appreciated
alihammadshah 3 years ago
thanks man. that's really helped.
KmOj 3 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
@ryutenchi wow, this was quite some time ago. I passed my C++ course, lol. Thanks!
btorrres18 8 months ago
Clearest Quality ever
Fr0stElite 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
Hello , I am a begginer and I want to start
which of your videos should I start from?
danielghofrani 3 years ago
how about the first one? they have each a unique number ;)
babo1990 3 years ago
nicely done, you have no ideea for how long i've been dieing to find out how to make dynamic arrays. You are making great tutorials keep it going
omutomata 3 years ago
Ah, didn't see that either but it says: 4Please give me the age of the person number 2.
GPadd 4 years ago
not a problem^^ glad you are paying attention. if there is a problem I need to know about it, right? Thanks for watching so closely!
ryutenchi 4 years ago
when u ran the program the first time, the 2nd age was different.
Guntobond 4 years ago
no, if you notice I typed that inital 4 faster then it output the second line to the screen, so if you pause it and look at the beginning of the line you'll see that 4. the cin looks at your input upto the [Enter] so even if you type before it gets all the text to the screen that "4" or whatever is already in the input buffer and then when you press [Enter] it flushes that buffer to that variable.
ryutenchi 4 years ago