I am seeking to learn C++. I am using the complex base class as source for this learning, by trying to adapt it to a template class. I am calling this class "plexmath". My effort follows ,but does not compile. I would like to retain the "protected" status of the variables "real" and "imag", and need to declare the Get_Real and Get_Imag functions so as to permit recall of the imaginary parts of the complex number as friend functions to do so. Unfortunately, I am having some trouble getting the syntax right by which to declare a template friend function that returns the templatized variable "whatever". Any suggestions would be very much appreciated.
Thanks!
Template Class (non-working) follows:
template <class whatever> class plexMath
{
protected:
whatever real;
whatever imag;
public:
// creates plexMath number
plexMath(whatever,whatever);
plexMath();
~plexMath()
{
}
friend whatever Get_Real(plexMath<whatever>);
friend whatever Get_Imag(plexMath<whatever>);
};
template <class whatever> plexMath<whatever>::plexMath(whatever thisreal, whatever thisimag)
{
real = thisreal;
imag = thisimag;
}
template <class whatever> plexMath<whatever>::plexMath()
{
}
template <class whatever> whatever Get_Real(plexMath<whatever> anum)
{
return anum.real;
}
template <class whatever> whatever Get_Imag(plexMath<whatever> anum)
{
return anum.imag;
}