P
philchen1978
Hi,
I can compile the code below with GCC 3.4.2, because function g is a
"dependent name".
template<class T>
void f1(T t)
{
g(t);
}
void g(int i)
{
}
int main()
{
f1<int>(10);
return 0;
}
But if I change the function g to a template function, things became
different. I cannot pass the compilation with GCC 3.4.2, but it works
fine with Visual C/C++ 7.
template<class T>
void f1(T t)
{
g<0>(t);
}
template<int I>
void g(int i)
{
}
int main()
{
f1<int>(10);
return 0;
}
The error message from GCC is:
main.cpp: In function `void f1(T)':
main.cpp:23: error: `g' undeclared (first use this function)
main.cpp:23: error: (Each undeclared identifier is reported only once
for each function it appears in.)
main.cpp: At global scope:
main.cpp:28: error: `template<int I> void g(int)' used prior to
declaration
Why?
Thanks,
Phil
I can compile the code below with GCC 3.4.2, because function g is a
"dependent name".
template<class T>
void f1(T t)
{
g(t);
}
void g(int i)
{
}
int main()
{
f1<int>(10);
return 0;
}
But if I change the function g to a template function, things became
different. I cannot pass the compilation with GCC 3.4.2, but it works
fine with Visual C/C++ 7.
template<class T>
void f1(T t)
{
g<0>(t);
}
template<int I>
void g(int i)
{
}
int main()
{
f1<int>(10);
return 0;
}
The error message from GCC is:
main.cpp: In function `void f1(T)':
main.cpp:23: error: `g' undeclared (first use this function)
main.cpp:23: error: (Each undeclared identifier is reported only once
for each function it appears in.)
main.cpp: At global scope:
main.cpp:28: error: `template<int I> void g(int)' used prior to
declaration
Why?
Thanks,
Phil