Thank you for hosting a place for beginners to write C++ questions! I'll try to not ask anything too absurd, but as I'm learning sometimes it's tough to know what is and is not absurd!
I would like to begin working with vectors and am following an online tutorial here:
In fact it appears the below code doesn't even address vectors yet but uses arrays, so the directive #include <vector> may be unnecessary here. Anyway, I get a number of errors with the code below, and I don't know what's causing it. I feel like it may be something very simple - like how it's arranged, but regardless of how I arrange it I get the following errors:
error: expected unqualified-id before 'for'
error: 'i' does not name a type
error: expected unqualified-id before '++' token
error: expected unqualified-id before 'delete'
The program leaks memory (no delete[] called on DynamicArray though it's there on the website) and typo on line 13 – return with lower-case 'r' – otherwise it works fine:
Sorry about the missing delete keyword, I removed it just before copying it to the post.
gunnerfunner: what you suggested seems to work, but I'm a bit mystified as to why it's working now and not before, as I'm *nearly certain* what I had was basically the same without the output.
Thanks again, I really appreciate the help on this!