By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Template class partial specialisation

P: n/a
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/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Adrian Hawryluk wrote:
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 NEEDEDclass MyTemplate
{
// plenty of stuff
};

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

Just a thought...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 19 '07 #2

P: n/a
Victor Bazarov wrote:
Adrian Hawryluk wrote:
>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 NEEDEDclass 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/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.