Issue with vector<vector<int> >

So, I'm trying to make a very simple class where I have a vector<vector<int> > that I am using as a 2d array, basically. The thing is I keep getting this error code on compilation from XCode and I'm not quite sure what I'm doing wrong.

Face.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Face {
	public:
		Face(int iNum, int size);

	private:
		int num;
		vector<vector<int> > colors;
};


Face.cpp
1
2
3
4
5
6
7
8
9
10
11
#include "Face.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

Face::Face(int iNum, int size) {
	num = iNum;
	colors = new vector<vector<int> >(size, vector<int>(size, iNum));
}


Error Code:
error: no match for 'operator=' in '((Face*)this)->Face::colors = ((((const __gnu_debug_def::vector<int, std::allocator<int> >&)((const __gnu_debug_def::vector<int, std::allocator<int> >*)(& __gnu_debug_def::vector<int, std::allocator<int> >(size, iNum, ((const std::allocator<int>&)((const std::allocator<int>*)(& std::allocator<int>()))))))), ((const std::allocator<__gnu_debug_def::vector<int, std::allocator<int> > >&)((const std::allocator<__gnu_debug_def::vector<int, std::allocator<int> > >*)(& std::allocator<__gnu_debug_def::vector<int, std::allocator<int> > >())))), (((__gnu_debug_def::vector<__gnu_debug_def::vector<int, std::allocator<int> >, std::allocator<__gnu_debug_def::vector<int, std::allocator<int> > > >*)operator new(28u)), (<anonymous>->__gnu_debug_def::vector<_Tp, _Allocator>::vector [with _Tp = __gnu_debug_def::vector<int, std::allocator<int> >, _Allocator = std::allocator<__gnu_debug_def::vector<int, std::allocator<int> > >](((long unsigned int)size), <anonymous>, <anonymous>), <anonymous>)))'
new is only used for pointers. If you want to call the constructor of the vector, you need to use an initializer list.
Lol thanks! I meant to be using a pointer -.-
Ah, well then that would explain the problem...although I am not really sure why you are using a pointer in this case...it probably wouldn't do anything but add extra memory (albeit a very small amount).
Yeah I'm a bit of a newb at this, lol.

So you mean something along the lines of this, right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Face {
	public:
		Face(int iNum, int size): colors(size, vector<int>(size, iNum)), num(iNum) {};

	private:
		int num;
		vector<vector<int> > colors;
};
Yeah that's good.
Topic archived. No new replies allowed.