I feel that you're trying to go about it the wrong way. You don't have to store it both ways around, and I don't see why you'd want to store vectors internally. All you'd need to do is to make your interface capable of allowing the accessing of the members to be in row or column major order.
I.e. try out the following code which for this example just stores ints and the matrix is 4x4 in size.
Code:
class constProxyAccessor {
const int *base, step;
public:
constProxyAccessor(const int *base, int step)
: base(base), step(step) {}
int operator[](int x) const {
return base[x * step];
}
};
class proxyAccessor {
int *base, step;
public:
proxyAccessor(int *base, int step)
: base(base), step(step) {}
int& operator[](int x) {
return base[x * step];
}
};
class transposableMatrix {
int m[16];
bool inverted;
public:
transposableMatrix() : inverted(false) {}
void invert() {
inverted = !inverted;
}
constProxyAccessor operator[](int x) const {
return inverted ? constProxyAccessor(&m[x*4], 1) : constProxyAccessor(&m[x], 4);
}
proxyAccessor operator[](int x) {
return inverted ? proxyAccessor(&m[x*4], 1) : proxyAccessor(&m[x], 4);
}
};
int main()
{
transposableMatrix mtx;
mtx[3][1] = 123;
mtx.invert();
int foo = mtx[1][3]; // foo is now 123!
mtx[2][0] = 456;
mtx.invert();
foo = mtx[0][2]; // foo is now 456!
}