jason wrote:

> I would like it if I could have a single class that is called - like so ...
> 
> public class myWidget : <relevant widget type>
> {
>       ... do stuff // few hundred lines of code
> }

template <typename T>
class myWidget:public T {
 ...
}

would do the job.

> 
> The thing is that I am going to have tens of widgets represented by an 
> individual
> class with hundreds if lines of the exact same code so
> it would be great if I could use templates here somehow.

When using templates it is good thing to avoid template-based bloat. If
your function would compile to the same "machine code", then it might be
better to define eg external function which takes a widget pointer as a
parameter, use a callback/plugin or something similar. The unnecessary
bloat might occur eg if you would use many base classes of the same root
and use the root class methods: it would unnecessarily reimplement the
function for each class, for each class it would create its own v-table
etc. If your function is only "syntactically the same" (looks the same),
but uses different implementation of non-virtual functions it calls,
then use of templates makes sense.

R.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to