I would like to know what the following paragraph means and how do I implement it. I asked a question yesterday related to the same issue here. In yesterday's question, I was told this is not possible but I think the following paragraph indicates it is?
Your methods use specific exponentiation methods. However, the exponentiation classes are subclasses of a general abstract exponentiation class. You could implement these to use this abstract class, and just instantiate that with one of the concrete classes. This would give you the flexibility to experiment with and/or change exactly what exponentiation algorithms are used, for example, if someone identifies something better in the future....
Essentially, I have a bunch of exponentiation techniques organized in the following manner-
template <class T>
class Exponentiation
{
public:
Exponentiation() {};
virtual ~Exponentiation() {};
// computes C = A^n
virtual void power(T& C, const T& A, const int n) = 0;
}
template <class T>
class ExpA : public Exponentiation<T>
{
public:
ExpA() {};
~ExpA() {};
void power (T& C, const T& A, const int n);
}
template <class T>
class ExpB : public Exponentiation<T>
{
protected:
var1;
var2;
public:
ExpB() {};
~ExpB() {};
func1();
func2();
void power (T& C, const T& A, const int n);
}
Now, initially I had a performExp()
that was calling specific exponentiation methods like -
performExp()
{
ExpA<long> objA;
objA.power();
// or
ExpB<long> objB;
objB.func1();
objB.func2();
obj.power ()
}
but from what I have been told, a better option is to use the base class in performExp()
and then instantiate the base class in main()
with one of the concrete classes ExpA
or ExpB
.
How does one go about doing this? One thought I have after reading yesterday's answers is to use some sort of wrapper but I am having a hard time to visualize it.