I know there are some template wizards around here so hopefully someone can help :-) I have a simple code example which I can't get to compile on both VS2010 and GCC. I can make simple changes to allow it to compile on either platform, but I haven't found the one correct solution which works on both. See the two commented lines in the code below:
template <typename Type>
class Base
{
public:
template <typename NestedType>
class Nested
{
};
};
template <typename Type>
class Derived : public Base<Type>
{
public:
class Nested : public Base<Type>::Nested< int > //This line works on VS2010
class Nested : public Base<Type>::template Nested< int > //This line works on GCC
{
};
};
int main(int argc, char** argv)
{
Derived<int>::Nested nested;
return 0;
}
In both cases, the line which works on one platform does not work on the other. If I get it the wrong way round the VS2010 error is:
error C2955: 'Base<Type>::Nested' : use of class template requires template argument list
And the GCC error is:
main.cpp:17: error: non-template ‘Nested’ used as template
main.cpp:17: note: use ‘Base<Type>::template Nested’ to indicate that it is a template
Any ideas what the correct syntax is?!
Thanks!