S
scorp007
Hi,
My problem is as follows. I am trying to have each of my classes in the
hierarchy have different behaviours which are set at compile time. I
also want to be able to treat the classes in the hierarchy uniformly
using polymorphism and this is where I run into problems. I'm not sure
how to go about declaring a pointer to the base type so that this
becomes possible.
I dynamically create objects that fall into the types A,B or C. The
types might be instantiated something like:
A<TypeOne> a;
B<TypeTwo> b;
C<TypeOne> c;
What then should the Base pointer type look like? Perhaps my design
isn't all that good but I couldn't really see another nice way to do
what I want. Inheritance wouldn't be very manageable although fairly
easy to implement.
The class hierarchy looks something like this:
template<class Type>
class Base
{
void function()
{
Type aType;
aType.doSomething()
}
};
template<class Type>
class A: public Base<Type>
{
};
template<class Type>
class B: public Base<Type>
{
};
template<class Type>
class C: public Base<Type>
{
};
class TypeOne
{
public:
void doSomething()
{
cout << "this is type one\n";
}
};
class TypeTwo
{
void doSomething()
{
cout << "this is type two\n";
}
};
Thanks for any help.
My problem is as follows. I am trying to have each of my classes in the
hierarchy have different behaviours which are set at compile time. I
also want to be able to treat the classes in the hierarchy uniformly
using polymorphism and this is where I run into problems. I'm not sure
how to go about declaring a pointer to the base type so that this
becomes possible.
I dynamically create objects that fall into the types A,B or C. The
types might be instantiated something like:
A<TypeOne> a;
B<TypeTwo> b;
C<TypeOne> c;
What then should the Base pointer type look like? Perhaps my design
isn't all that good but I couldn't really see another nice way to do
what I want. Inheritance wouldn't be very manageable although fairly
easy to implement.
The class hierarchy looks something like this:
template<class Type>
class Base
{
void function()
{
Type aType;
aType.doSomething()
}
};
template<class Type>
class A: public Base<Type>
{
};
template<class Type>
class B: public Base<Type>
{
};
template<class Type>
class C: public Base<Type>
{
};
class TypeOne
{
public:
void doSomething()
{
cout << "this is type one\n";
}
};
class TypeTwo
{
void doSomething()
{
cout << "this is type two\n";
}
};
Thanks for any help.