Re: compile time detection of multiple template class usage
On Jun 29, 3:09 pm, "alexandru.nicau" <alexandru.ni...@gmail.com>
wrote:
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.
Let me guess: You are trying to deny access to the wrapped variables
when the parent object is const? The code below seems to work. The
macro will be different if you use a template, but you get the idea.
This provides errors upon attempted instantiation which should lead
back to the embedded declaration.
class wrapper_user
{
protected:
template <class Type>
class wrapper
{
Type local;
public:
Type &get() { return local; }
};
};
#define STRUCT_WRAPPER(name) class name; \
template <> class \
wrapper_user::wrapper < name > \
{ virtual void INVALID_EMBEDDING() =
0; }; \
struct name : public wrapper_user
STRUCT_WRAPPER(test_class1)
{
wrapper <int> value;
};
STRUCT_WRAPPER(test_class2)
{
wrapper <test_class1> invalid;
};
int main()
{
test_class1 test1;
test_class2 test2;
test1.value.get();
test2.invalid.get();
}
Kevin P. Barry
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]