Solved
What a way is more OOPer ?
Posted on 2002-07-06
I must to implement Quaternion and Complex numbers classes. I began so:
template <class T>
class Quaternion
{
public:
...
Quaternion(); // few kinds of Ctors
...
private:
T w,x,y,z; // w+xi+yj+zk;
};
I have 3 ways to continue:
1-st way:
template <class T>
class Complex1
{
public:
...
Complex1(); // few kinds of Ctors
...
pirvate:
Quarterion<T> q; // I use the q as complex number
// and its y,z fields initialized by zero;
};
2-nd way:
template <class T>
class Complex2:public Quarterion<T>
{
public:
...
Complex2(T a, T b):Quarterion(a,b,0,0){}
// yet few needed Ctors
...
};
3-rd way:
template <class T>
class Complex3:private Quarterion<T>
{
// Additional question (accordingly I add points):
How can I to declare here function from Quarterion class so that they should public (I don't want that user of Complex3 class should be able to use function from Quarterion beside of function I'll permit for using)?
};
What way from these is prefer ?
Thank you.