cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
vectors inside classes
vectors inside classes
Oct 27, 2008 at 2:19am UTC
Inebas
(8)
Hi guys,
I'm new here and just beginning to learn C++.
I'm trying to create a vector inside a class and it's giving me lots of errors. For example,
#ifndef DATABASE_H_
#define DATABASE_H_
//#include <vector>
class Database {
public:
Database();
virtual ~Database();
vector<string> firstName;
vector<string> lastName;
vector<string> City;
vector<int> zipCode;
...
and the list goes on.
Please advice. Thanks.
Oct 27, 2008 at 3:59am UTC
Timaster
(52)
I really hope this isn't your error, but your #include <vector> is commented =P
Oct 27, 2008 at 1:47pm UTC
jsmith
(5804)
That would likely do it, although you probably also need to use std::.
Also, you need to #include <string>.
eg,
std::vector<std::string> firstName;
Oct 27, 2008 at 4:18pm UTC
Inebas
(8)
Thanks a lot. That indeed work. I didn't include it initially because I have a separate class.cpp and class.h and the #include <vector and #include <string> and using namespace std are all included in the main.cpp
Cheers!
Topic archived. No new replies allowed.