I am implementing an algorithm, which is general for various types of
entities (neurons in neural network). And I would like to easily reuse
this algorithm for the new types of neurons in the future. I would like
my library be similar to STL, but with its own algorithtms. So,
t->do_it() will work of course, but my purpose is to create a library
of algorithtms. I already have a working version with virtual methods
(in Delphi), but it's now clear for me that the additional level of
abstraction I have is unnecessary because I'm not really in a situation
when the entities (neurons) may be replaced dynamically. Thank you! I
would also like to slightly change my initial question:
Is it _normal_ to do something like the following? Isn't it a bad
_style_ of using C++?
template<class T>
void just_do_it(T* t)
{
t->do_it();
}
For example, STL algorithms require container items to have operators
, <, = implemented right. So I suppose I can require my template
classes to have a method I want (like above). Good style or bad?
It seems to me that generic programming requires more thorough studying
than I did before. For example, the code above is somehow similar to
requiring interface implementation without having the interface itself.
This is really interesting alternative... Wow!