I stumbled across what seems to me a very interesting problem. I am not asking for a solution to this problem, only advices on how to continue with my code and I'd like to know if derived classes inherit the friends of the base class.
This is the problem:
Class matrix, friend of class array is the base class for the class diagonal_matrix. The derived class must contain a parameterized constructor through which to highlight the transmission of parameters towards the constructor from the base class, destructor and a method to check if the matrix is square and diagonal ( all elements other than the ones from the principal diagonal are equal to zero). Illustrate the concept of virtual function (pure if it's more natural in implementation).
This is what I wrote so far (not very creative today on how to continue):
#include <iostream>
using namespace std;
class arry
{
private:
int *vec;
int n;
public:
int i,nrelem;
arry(){};
~arry();
void readArray(int);
};
arry::~arry()
{
n=0;
delete [] vec;
}
void arry::readArray(int elem)
{
n=elem;
vec=new int[n];
for(i=1;i<=elem;i++)
{
cout<<"vec["<<i<<"]=";
cin>>vec[i];
}
}
class matrix
{
public:
friend class arry;
matrix(int , int);
~matrix();
};
int main()
{
return 0;
}