Error while declaring a vector of a vector of strings in my class

Yeah...this project got a bit more complex than I would have thought. But oh well.

I'm trying to make a trivia game for a programming project. I was going to use a vector of vector of strings (i.e. 2 dimensional array, where there is a row of vectors that are made up of strings). However, whenever I try to compile, I'm getting errors:

error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'

Here's the header and implementation so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef TRIVIA_SPROUL_TRIVIA_H
#define TRIVIA_SPROUL_TRIVIA_H
#include <vector>	// Provides vector class
#include <string>	// Provides string class
#include <cstdlib>	// Provides size_t

namespace trivia_sproul
{
	class trivia
	{
	public:
		// CONSTRUCTOR
		trivia();

		// MODIFICATION MEMBER FUNCTIONS

		// CONSTANT MEMBER FUNCTIONS

	private:
		vector < vector<string> > questions;
		size_t score;
		size_t progress;
		bool fifty_fifty;
		bool expert;
	};
}

#endif


And the implementation...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include"trivia.h"
using namespace std;

namespace trivia_sproul
{
	trivia::trivia()
	{
		score = 0;
		progress = 0;
		fifty_fifty = true;
		expert = true;
	}



}


This just produces the errors that I've listed above. Normally this wouldn't seem strange at all to me, because I'm using vector and string for the first time. However, the following program works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
	vector < vector<string> > str;

	str.push_back(vector<string>(2));
	str.push_back(vector<string>(2));

	str[0][0] = "Hi";
	str[1][1] = "Hello";

	cout << str[0][0] << endl;
	cout << str[1][1] << endl;

	return 0;
}


That just writes:
Hi
Hello
to the screen. I don't really see what I'm doing differently. Could somebody give me a hand?
vectors and strings are in the std namespace.

Change your class to this:

 
std::vector < std::vector<std::string> > questions;  // note the std:: prefixes 

Topic archived. No new replies allowed.