Be careful with member references! If the referred-to object is cleaned up before the instance of MyClass is, you will have an invalid reference. Often (but not always), if you find that you need to use a member reference, it is an early warning sign that your design could be improved. I rarely use member references for anything other than as a handle to an object's owner, where I can be absolutely certain that the referred-to object will outlive the reference.
It might help if you change slightly your class' responsibilities. Right now, you are building up a set of data, and then creating an object to which you pass that set of data. Instead, why not first build the object, then put the data directly into it.
// To start, define your class to allow you to build up the data
class MyMatrix
{
public:
MyMatrix ()
{ }
void setData (int x, int y, int data)
{ this->myData [x][y] = data; }
int getData (int x, int y)
{ return this->myData [x][y]; }
private:
vector<vector<int> > myData;
}
// Then, create a vector of 6 (or however many you need) matrices
int numberOfMatrices = 6;
vector<MyMatrix> myCube (numberOfMatrices);
// Then, fill in the vector
for (int matrixIndex = 0; matrixIndex < numberOfMatrices; matrixIndex++)
{
// Fill in the data for this matrix
MyMatrix ¤tMatrix = myCube [matrixIndex];
currentMatrix.setData (0 /* x */, 0 /* y */, 0 /* data */);
// ... rest of data
}
Then, you have all the data already in your objects, ready to be processed as you need. Plus, each object owns its data, so as long as the object is around, its member data will be valid. Best of all, using objects with usefully named member functions will make your code much more self-documenting than tons of nested containers.