I have one (abstract) parent class and some more children classes.
template <typename T>
class parent {
public:
T data;
virtual T method(T t) = 0;
};
template <typename T>
class child : public parent<T> {
public:
child(){
cout << "test" << endl;
}
T method(T t){
cout << t << endl;
}
};
template <typename T>
class child2 : public parent<T> {
public:
child2(){
cout << "test2" << endl;
}
T method(T t){
cout << "other" << endl;
}
};
Then I have a main Class that has a pointer to an array of parent pointers
template <typename T>
class mainClass{
public:
mainClass(){
ptr = new child<T>[10];
for (int i = 0; i < 10; i++)
{
ptr[i] = NULL;
}
}
parent<T>** ptr;
};
Now, I dynamically want to assign this array to a certain child class.
ptr = new child<T>[10];
But somehow this does not work.
error: incompatible pointer types assigning to 'parent<int> **' from 'child<int> *'
What should I do ? If you need any clarifications let me know Thanks in advance.
Jonny