Hello,
I have some code, which compiles with g++ 3.2-4.0 and msvc 7.x-8.x. It
does not compile with the latest g++ 4.1.1. Example:
#include <vector>
inline void y(int i)
{
}
template <class T>
void y_iter(T begin, T end)
{
for(; begin != end; ++begin)
y(*begin);
}
template <class T>
void y(const std::vector<T> &v)
{
y_iter(v.begin(), v.end());
}
void x()
{
std::vector<std::vector<int> > z;
y(z);
}
I get this error:
x.cpp: In function âvoid y_iter(T, T) [with T =
__gnu_cxx::__normal_iterator<const std::vector<int, std::allocator<int>
>*, std::vector<std::vector<int, std::allocator<int> >,
std::allocator<std::vector<int, std::allocator<int> > > > >]â:
x.cpp:17: instantiated from âvoid y(const std::vector<T,
std::allocator<_CharT> >&) [with T = std::vector<int,
std::allocator<int> >]â
x.cpp:23: instantiated from here
x.cpp:11: error: cannot convert âconst std::vector<int,
std::allocator<int> >â to âintâ for argument â1â to âvoid y(int)â
It seems as if symbol resolving has moved from template instantiation to
template definition time (just like "normal" functions). Is there a way
to avoid this issue for such recursive template instantiations? I have a
lot of code that depends on this approach...
Thanks,
Egon Kocjan