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

compile time detection of multiple template class usage

P: n/a
Hello All,
I've got this huge class hierarchy (the naive solution to the
following cannot be accepted). Throughout the code I need to
instantiate a template wrapper class at several locations. Easy does,
I change the code and wrap all the members I want into TmplWrp. Assume
it's bad if I've got some member wrapped into TmplWrp then one of its
descendants (think of class members - not of inheritance) also wrapped
into TmplWrp.

Can you think of any solution where I'll be able to determine such
pairs or even chains (the wrappee contains members, the members
contain other members to a point where there is another object wrapped
with TmplWrp) at compile time? Runtime can be easily implemented by
using some static.

The template wrapper:

template <class T>
class TmplWrp
T local;
TmplWrp(const T cp = T()) : local(cp)

T &Get()
return local;

Existing class hierarchy:

class c1
int a;

class c2 : public c1
int b;

class c3
int c;
c2 member_c_2;

If I change c1::a declaration to TmplWrp<inta and c3::member_c_2
declaration to TmplWrp<c2member_c_2 we're in the invalid situation
where I need warning. But if only c1::a and c2::b are wrapped in
TmplWrp we're ok: no warning should be given because the two are on
the same level (inheritance).
Thanks in advance,

Jun 27 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.