I am having some trouble with vector declarations in the header file of a C++ class I am making. My entire header file looks like this:
#ifndef PERSON_H #define PERSON_H #include "Message.h" #include <string> #include <vector> class Person { public: Person() {}; Person(std::string emailAddress); private: vector<Message> inbox; vector<std::string> contacts; std::string emailAddress; }; #endif PERSON_H
My error occurs on the lines following the "private" declaration (where I declare my vectors). The error I am getting is C4430 - missing type specifier and and C2238 - unexpected tokens preceding ';'
Thank you for any help.
The header file for the STL vector library is vector. (Note that when using C++, header files drop the . h; for C header files - e.g. stdlib.
A global array does not have to be declared in a header file. However, doing so allows the array to be used, without having to copy/paste the declaration to everywhere it is needed.
By writing #include <vector> , you are telling the compiler to not only use your own code, but to also compile a file called vector .
You're missing the namespace:
std::vector
You need to put 'std::' before 'vector' just like you did with string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With