I recently reopened a visual studio project I last worked on a year ago, and I want to get it to compile under g++. Among other issues, the compiler complains about some template code that doesn't appear legal in the first place.
Specifically, some of the template class method's instantiate Iterators for their class that are defined lower down, with no forward declarations. This would not be a problem if I was not working with templates, because the class declarations themselves are perfectly legal; it's the method bodies, which would ordinarily be in source files, which are causing problems. It seems as though templates compile differently to account for this, at least under msvc.
Sample code:
template<class T>
class ClassA : public HasIterator<T>
{
public:
Iterator<T> * GetIterator()
{
return new ClassAIterator<T>(this);
}
};
template<class T>
class ClassAIterator : public Iterator<T>
{
ClassA *foo;
public:
AggregateWrapperIterator(ClassA *foo)
{
//...
}
bool HasNext()
{
//..
}
T Next()
{
//..
}
};
I'd just add forward declarations but it get's complicated because of inheritance (there was a reason I set it up this way in the first place).
My question is this: for what reason does msvc allow this code, and does g++ have similar support?