Hi, not sure if I am interpretting the meaning of the word nested properly.
However, this is how I did nested (as I understand the word) templates in Visual studio 2008.
1 2 3 4 5 6 7 8 9 10 11 12
template <class ElementOfCommutativeRingWithIdentity>
class Monomial{};
template <class ElementOfCommutativeRingWithIdentity,
template<typename RingElementMonomial> class TemplateMonomial>
class TemplatePolynomial: public HashedListBasicObjects <TemplateMonomial<ElementOfCommutativeRingWithIdentity> >
{};
template <class ElementOfCommutativeRingWithIdentity>
class Polynomial: public TemplatePolynomial<ElementOfCommutativeRingWithIdentity,Monomial>
{
};
Notice there is a difference in the use of <typename T> and <class T>. What it is exactly I don't know. I once landed on a link (which started somewhere from this forum) explaining that the syntax is so because they had problems making the compiler run efficiently if they used a more reasonable syntax.
PS. Sorry for the long class names. This is how I like them.
Note:
1. This is valid: template <typename TTT, template <typename TT> class T>
2. This is NOT valid template <typename TTT, template <typename TT> typename T>
I just remembered that was a difference between class and typename
Single argument templates. The class is a template, and the class has a member function that's also a template. Each template can be its own type (ie: MyClass<int>::myfunc<float>)
I'm not looking for a template argument that's a template.
I don't know how to be more specific. Words are failing me, apparently XD. I appreciate all the effort, though.
EDIT--
upon a bit more testing... implicitly inlining the function works fine:
1 2 3 4 5 6 7 8 9 10 11 12
// This code compiles fine in GCC and VS
template <typename T>
class C
{
public:
template <typename TT>
T func(TT v)
{
cout << "called\n";
return 0;
}
};
But how would I go about moving 'func's body so it's not implicitly inlined?
Did you experiment with this syntax template <typename TT,typename T> instead of template <typename T1> template <typename T2>?
P.S. all of the suggestions so far compile on my VS...
Alright that's what I figured. I'm fine if that was the case.
I would update my VS if I thought I could without updating my OS (my windows box still has Win2k and I don't feel like shelling out a few hundred to upgrade to an OS I'll hardly ever use)
I'm having a few more template related errors (like it failing to instantiate templates when there's no reason it shouldn't be able to). I'm wondering if those are just because it's outdated as well.
Bah.
Anyway thanks for the help. I suppose I'll try updating VS on this comp. If it works, then yay.