I have a piece of code that compiles using icc or visual c++ but does not when I use gcc or clang.
The problem comes from the fact that gcc/clang want bindTo(std::string& s, const int& i)
to be defined before A<T>::bind(T& t)
or callBindTo(T& t)
definition and not just before code instantiation.
My question is: Why Visual and icc does not require it ? and which compiler have the right behavior with respect to the standard ?
#include <string>
template <typename T>
class A
{
public:
static void bind(T& t);
};
template <typename T>
void A<T>::bind(T& t)
{
std::string s;
bindTo(s, t);
}
template <typename T>
void callBindTo(T& t)
{
std::string s;
bindTo(s, t);
}
void bindTo(std::string& s, const int& i)
{
s = i;
}
int main()
{
int i;
A<int>::bind(i);
callBindTo(i);
}