Hey!
I'm new to c++, and I'm working with a program to print a vector with random values from 0 to 100. When I try to run the program, I get the following errors:
The reason why I have so many different cpp and header files is because it's a part of a bigger task. There might of course be some logical errors as well..
Sorry if it's a messy post, but I appreciate all answers!
the int error is a compiler spasm left over from the vector confusion. As a rule of thumb, fix the top error and try again unless its a very lengthy compile time program (millions of lines stuff).
ditto for the next error. It couldn't figure out the function from the vector error so it didnt register the function name ... error cascading ... you get used to it :)
consider using <random> instead of C's random tools.
Thanks for the tips!
However, I still get the same errors after including vector..
Am I supposed to use the #include <vector> in the headers as well?
I tried both including in the header and not, but it didn't seem to work
well, that is a loaded question :)
you can 'get away' with include chains... that is, if header B includes header A that includes Vector, B will be fine if it uses vector. This is bad practice, but it happens from time to time.
The right thing to do is: if a file uses something, you include it in that file.
Your own headers should have include guards (these let the compiler handle it if you include it more than once in the same program) and all the standard ones have this taken care of for you.
all that to say include vector anywhere you used a vector (in the header, and not in the related cpp file is ok, but each header that has a user should have it).
pragma once is, by the way, a microsoftism for an include guard.
Thanks again, you are really helping me understand how this works!:)
The code is running now btw, just had to adjust the including stuff a little (just as you said).