A
Adam Nielsen
Hi everyone,
Yet another syntax problem that's baffling me with templates. I want to
instantiate a template with a single parameter as per normal, however
the parameter is actually a template class itself, with all *its*
parameters filled out (in the form of a typedef.) I can't work out how
to break apart the typedef to reveal what data types were used to create
it in the first place.
Here is some example code that demonstrates the problem. I've tried
every syntax I can think of but I haven't managed to hit upon the right
one yet! Any suggestions would be much appreciated.
Many thanks as always,
Adam.
#include <iostream>
template <class TFrom, class TTo>
class CLinkData;
class A { };
class B { };
typedef CLinkData<A, B> MyLink;
// How do you declare the template to accept a CLinkData parameter, but
// broken out into its component types?
//template <template <class TLinkFrom, class TLinkTo> class TLinkData>
//template <template <class TLinkFrom, class TLinkTo>
// class TLinkData<TLinkFrom, TLinkTo> >
template <class CLinkData<TLinkFrom, TLinkTo> >
void createStoredLink(void)
{
std::cerr << "CLinkData types are " << typeid(TLinkFrom).name() <<
" and " << typeid(TLinkTo).name() << std::endl;
// TLinkFrom should be A, and TLinkTo should be B, the types used
// to declare MyLink.
return;
}
int main(void)
{
createStoredLink<MyLink>();
return 0;
}
Yet another syntax problem that's baffling me with templates. I want to
instantiate a template with a single parameter as per normal, however
the parameter is actually a template class itself, with all *its*
parameters filled out (in the form of a typedef.) I can't work out how
to break apart the typedef to reveal what data types were used to create
it in the first place.
Here is some example code that demonstrates the problem. I've tried
every syntax I can think of but I haven't managed to hit upon the right
one yet! Any suggestions would be much appreciated.
Many thanks as always,
Adam.
#include <iostream>
template <class TFrom, class TTo>
class CLinkData;
class A { };
class B { };
typedef CLinkData<A, B> MyLink;
// How do you declare the template to accept a CLinkData parameter, but
// broken out into its component types?
//template <template <class TLinkFrom, class TLinkTo> class TLinkData>
//template <template <class TLinkFrom, class TLinkTo>
// class TLinkData<TLinkFrom, TLinkTo> >
template <class CLinkData<TLinkFrom, TLinkTo> >
void createStoredLink(void)
{
std::cerr << "CLinkData types are " << typeid(TLinkFrom).name() <<
" and " << typeid(TLinkTo).name() << std::endl;
// TLinkFrom should be A, and TLinkTo should be B, the types used
// to declare MyLink.
return;
}
int main(void)
{
createStoredLink<MyLink>();
return 0;
}