I’m new to C++, and I’m trying to simply pass an array to a class constructor whilst using object-oriented programming, but I keep getting the error “C2040 ‘matPtr’: ‘Matrix3D’ differs in levels of indirection from ‘float *'”. Here is the code:
Main.cpp –
#include <GL/glut.h>
#include "Matrix3D.h"
void display(void) {
//...
float mat[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
float* matPtr = &mat[0][0]
Matrix3D(matPtr);
//...
}
int main(int argc, char** argv) {
//OpenGL stuff not really being used at the moment...
glutDisplayFunc(display);
//...
}
Matrix3D.h –
#include <GL/glut.h>
#include <iostream>
#ifndef __MATRIX_H__
#define __MATRIX_H__
class Matrix3D {
private:
float mat[3][3] = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} };
public:
Matrix3D() {}
Matrix3D(float* matPtr) {
for (int i = 0, n = 0; i < sizeof(this->mat) / sizeof(this->mat[0]); i++) {
for (int j = 0; j < sizeof(this->mat[0]) / sizeof(this->mat[i][0]); j++, n++) {
this->mat[i][j] = *(matPtr + n);
}
}
//Print array code...
}
};
#endif