I have an inherited class for making complex matrices (from a parent matrix class). The idea was to create two objects from the parent class for real and complex parts of the matrix. I am kind of confused on how to make the constructor. The code is :
template <class type>
class complexMatrix: public matrix<type>
{
public:
matrix<type> Real;
matrix<type> Complex;
complexMatrix() //Default Constructor
{
matrix<type> Real;// Call the matrix class constructor by default
matrix<type> Complex;
}
complexMatrix(int rows,int columns, string name) //Creat a complex matrix
{
string name_real,name_complex;
name_real = name;
name_complex = "i"+name;
matrix<type> Complex(rows,columns,name_complex); // Create Imaginary matrix
matrix<type> Real(rows,columns,name_real);
}
void complexrandomize()
{
Real.matrix<type>::randomize();
Complex.matrix<type>::randomize();
}
};
This code obviously doesn't work. In an answer I found here on stackoverflow, I understood that I can initialize two objects from the parent and then call it using Real(rows,columns,name). In my case however, this won't work because I needed the () operator to be overloaded. So that solution is out of the question. Another solution I can think of is creating the objects Real and Complex within the constructor and manually copying all the values in the Real and Complex member objects. This doesn't sound like a great solution somehow.
Does anyone have a better way to go about this problem?