Template class partial specialisation

A

Adrian Hawryluk

I have a template class that takes multiple parameters, most of which
are optional.

99.8% of the body is the same though use of typedefing. Is there a way
of not having copy code the body of the class? The only two ways I've
thought of is using a define for the body, or using a separate file
which I use to include (or include the same file and use #if/#endif to
paste the body in.

I'm not sure if either is appropriate. Any comments?


Adrian
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/by-nc-sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
 
V

Victor Bazarov

Adrian said:
I have a template class that takes multiple parameters, most of which
are optional.

99.8% of the body is the same though use of typedefing. Is there a
way of not having copy code the body of the class? The only two ways
I've thought of is using a define for the body, or using a separate
file which I use to include (or include the same file and use
#if/#endif to paste the body in.

I'm not sure if either is appropriate. Any comments?

Have you tried inheritance?

template<class NEEDED> class MyTemplate
{
// plenty of stuff
};

template<class NEEDED, class OPTIONAL1, int OPTIONAL2>
class MyTemplate<NEEDED,OPTIONAL1,OPTIONAL2>
: public MyTemplate<NEEDED>
{
// whatever
};

Just a thought...

V
 
A

Adrian Hawryluk

Victor said:
Have you tried inheritance?

template<class NEEDED> class MyTemplate
{
// plenty of stuff
};

template<class NEEDED, class OPTIONAL1, int OPTIONAL2>
class MyTemplate<NEEDED,OPTIONAL1,OPTIONAL2>
: public MyTemplate<NEEDED>
{
// whatever
};

Just a thought...

Thanks. It took a lot of thinking about but I'm *a lot* closer now.
I'm only down to a few constructor deferrals. Not a perfect solution,
but no solution ever is, and I think it is the closest that I can get.

Thanks for the suggestion.


Adrian
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/by-nc-sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top