passing a multiple vector

Hi,

I have a class that generate a 2D vector of String

vector<vector<string> > matrix;

In the same class I have get and set method for that field:

1
2
3
4
5
6
7
8
9
const vector<vector<string> >& getMatrix() const 
{
	return matrix;
}

void setMatrix(const vector<vector<string> >& matrix)
{
	this->matrix = matrix;
}


The matrix i correctly generated but if I try to get that matrix into another class I get an empty vector.

vector<vector<string> > matrix = r.getMatrix();

How can I pass this matrix to other classes?

Thanks

LuKe
Show the code of the class method where you are trying to do that.

I think that the problem is that you defined a local vector and assigned to it a matrix of an other object. You have to use the member matrix instead of the local matrix. That is instead of

vector<vector<string> > matrix = r.getMatrix();
you have to write

matrix = r.getMatrix();
Last edited on
closed account (o3hC5Di1)
Hi there,

The return type of getMatrix is a reference, but you are returning the actual matrix for as far as I can see.
Try following declarator:

const vector<vector<string> > getMatrix() const

All the best,
NwN
I've tried both suggestions without success.
closed account (o3hC5Di1)
Could you supply your full (relevant) code please?

All the best,
NwN
I've solved!

It was my mistake: I had declared two time the same variable!
Topic archived. No new replies allowed.