You could make getCurrent a virtual function. I believe this should work:
...
Note that if you don't need to work with parent pointers to child instances,
simply overloading the getCurrent function would work.
On second thought, I think it would be better to write code
based on abstractions (parent pointers, parent link pointers, etc...)
and use virtual functions whenever you want child specific behavior.
I mean, you could write your code in a way that you don't have to
make such an assignment ->
child::node* test=ch.getCurrent();
.
child::nodes should not appear outside the respective child class.
Neither should child classes appear in main, except perhaps from the part where they are
created (which could also be encapsulated inside a factory, thus hidden from client code)
As for the other problem, you could provide (virtual) get/set functions.
Ramses12 wrote: |
---|
The only difference between sections is the specificity of the data, and maybe
some functions related to optimisation and all sorts of general data management. |
Consider something like this, then, where Data is a class
encapsulating the data specific stuff you mentioned:
1 2 3 4 5 6 7 8 9
|
class parent {/*...*/};
template <class Data>
class child : public parent
{
Data data;
//...
};
|