24

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.

3
  • 1
    The answer has already been found and the problem was due to programmer negligence. Thanks for the feedback and sorry to post such a silly question on this site. Commented Nov 19, 2010 at 23:43
  • Don't you love how useless the compiler error is, after 5 years of C/C++ it's become almost second nature, but after a while using java it just strikes how useless the compiler erro is. Commented Nov 20, 2010 at 0:04
  • I don't think it was silly. I'm pretty new to C++ and I was making the same mistake, so this was just what I needed! Commented Jul 31, 2016 at 3:40

3 Answers 3

33

You're missing the namespace:

std::vector 
Sign up to request clarification or add additional context in comments.

3 Comments

Arg, I feel like such a dunce. Thank you for pointing that out to me and sorry to everyone for clogging the site with such a silly question.
Compared to many questions here, it wasn't that silly :) You get extra points for not putting using namespace std; :)
Hah, I'll take that. :P I'll give you the green check since you answered first.
15

You need to put 'std::' before 'vector' just like you did with string.

1 Comment

Ah, of course. Gah, now I feel so foolish. Thanks for the help!
1

In my case, adding the namespace did not work, however, I was missing the

#include <vector>; 

1 Comment

Should be #include <vector> (with no semicolon)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.