I have a class that looks like this:
class Base
{
public:
Base( int val = 0 ) : value( val ) {};
int value;
};
Classes A
and B
inherit Base
:
class A : public Base {};
class B : public Base {};
I also have a templated class with a signature similar to:
template < class T >
class Temp
{
public:
Temp ( const T & val = T() ) : m_T( val ) {};
T m_T;
};
What I am trying to do is have a function that takes pointers to Temp<Base>
instances and act upon them:
void doSomething ( Temp< Base > * a, Temp< Base > * b )
{
(*a) = (*b);
};
Ultimately, I would like to have Temp<A>
and Temp<B>
instances passed to doSomething()
, like:
void
main()
{
Temp<A> a;
Temp<B> b;
doSomething( &a, &b) ;
};
Obviously, this will not work because Temp<A>
and Temp<B>
are not related and there is no implicit conversion between the types (even though A
and B
are Base
).
What are some of the ways this problem could be solved? Any input would be greatly appreciated.
Thanks in advance for your help.