Visual Studio kompiluje ten kod dobrze, ale gcc pozwala tylko na kompilację bez operatora szablonu. Za pomocą operatora Szablon daje następujące błędy:Problem z szablonem GCC
Wiersz 29: błąd: oczekiwano `; ' przed "itrValue"
class Test
{
public:
Test& operator<<(const char* s) {return *this;} // not implemented yet
Test& operator<<(size_t s) {return *this;} // not implemented yet
Test& operator<< (const std::list<const char*>& strList)
{
*this << "count=" << strList.size() << "(";
for (std::list<const char*>::const_iterator itrValue = strList.begin();
itrValue != strList.end(); ++itrValue)
{
*this << " " << *itrValue;
}
*this << ")";
return *this;
}
template <class T>
Test& operator<< (const std::list<T>& listTemplate)
{
*this << "count=" << listTemplate.size() << "(";
// this is line 28, the next line is the offending line
for (std::list<T>::const_iterator itrValue = listTemplate.begin();
itrValue != listTemplate.end(); ++itrValue)
{
*this << " " << *itrValue;
}
*this << ")";
return *this;
}
};
Nawet jeśli odpowiedź została już dostarczone przez Pieter, gdy mówimy o zachowaniach kompilatora ważne jest, aby określić dokładną wersję kompilatora ponieważ różne wersje mają różne zachowania (g ++ 4.0 narzeka na wiele innych rzeczy) –