Please help me correcting following error.
Error 1 error C2248: 'SquareMatrix::SquareMatrix' : cannot access private member declared in class 'SquareMatrix'
I am trying to implement a subclass(square matrix) under class(matrix) and I don't know how to fix the error. Here is the code.
#ifndef _MATRIX_
#define _MATRIX_
#include <iostream>
#include <vector>
using namespace std;
//class matrix starts here
template<class T, int m, int n>
class Matrix{
vector<vector<T>> elements;
int nrow;
int ncol;
public:
Matrix();
~Matrix();
template<class T, int m, int n>
Matrix<T, m, n>::Matrix() : nrow(m), ncol(n){
for (int i = 0; i < nrow; i++){
vector<T> row(ncol, 0);
elements.push_back(row);
}
}
template<class T, int m, int n>
Matrix<T, m, n>::~Matrix(){}
//here is the inheritance class SquareMatrix
template<class T, int n>
class SquareMatrix : public Matrix<T, n, n>{
SquareMatrix();
};
template<class T, int n>
SquareMatrix<T, n>::SquareMatrix() :nrow(n), ncol(n){
for (int i = 0; i < nrow; i++){
vector<T> row(ncol, 0);
elements.push_back(row);
}
}
//Here is the main.cpp
#include "Matrix.h"
using namespace std;
int main(){
Matrix<double, 3, 2> a;
SquareMatrix<double, 3> c;
}