Using both Visual Studio and gcc is a known issue :) And I used VS2003 and gcc 3.4.2, so it was a while.
If I remember correctly, the problem is related to the way the patterns are analyzed on these compilers.
gcc behaves as specified by the standard and performs 2 parses:
- the first, when it encounters a template, without any type information, at that moment several magicians
typename and template required to help understand what is happening - second when the template instance with the specified type is actually created
on the other hand, VS does only one parsing at instantiation and therefore can fully resolve characters without typename and template here and there.
You have the same for methods:
template <class Item> struct Test { template <class Predicate> void apply(Predicate pred); void doSomething { this->apply(MyPredicate()); }
In the same topic, if you are doing something like:
template <class Item> struct Test { static const std::string Name; };
You need to define this static attribute for each instance of the template, or you will have an undefined character.
VS accepts this syntax:
const std::string Test<MyType>::Name = "MyType";
But gcc asks for a little keyword:
template <> const std::string Test<MyType>::Name = "MyType";
You can think of VS as the best, as it asks you less, but, on the other hand, gcc can warn you about errors in your template methods / classes as soon as it analyzes them for the first time (i.e. without any actual instantiation) and personally, the sooner the better.
Obviously, the good news is that if compiling on gcc (for these problems), it will also compile in Visual Studio.
Since I'm not standardized, I'm not sure if the standard really requires or recommends a 2-pars scheme.