F
Fernando Cuenca
Hi,
I'm trying to explicitly instantiate a template function using the
following syntax:
obj.template_func<type>(params);
It compiles OK when used from a regular function, but it doesn't
compile when used in a template function. Is there any particular
reason for this, or is this a compiler bug? I'm using GCC 3.2.3 on
Debian Linux.
An example program follows here:
//---------------------------------------------------------------
#include <iostream>
using namespace std;
class Test
{
public:
template<class T> void DoIt(int i)
{
T aT = 0;
cout << aT << " " << i << endl;
}
};
class Test2
{
public:
template<class T> void CallIt(int i)
{
Test aTest;
//THIS DOESN'T COMPILE: aTest.DoIt<T>(i);
}
void CallIt2(int i)
{
Test aTest;
aTest.DoIt<float>(i); // HERE IT COMPILES OK
}
};
int main()
{
Test2 aTest;
//aTest.CallIt(1);
aTest.CallIt2(2);
return 0;
}
//---------------------------------------------------------------
In this example, the CallIt function doesn't compile, but CallIt 2,
which uses the same syntax, but it's not a template itself, compiles
fine.
The error message I get is:
tmplt.cpp: In member function `void Test2::CallIt(int)':
tmplt.cpp:24: syntax error before `;' token
Thanks in advance!
Fernando Cuenca.
(mail to: fernando_cuenca *at* yahoo *dot* com *dot* ar)
I'm trying to explicitly instantiate a template function using the
following syntax:
obj.template_func<type>(params);
It compiles OK when used from a regular function, but it doesn't
compile when used in a template function. Is there any particular
reason for this, or is this a compiler bug? I'm using GCC 3.2.3 on
Debian Linux.
An example program follows here:
//---------------------------------------------------------------
#include <iostream>
using namespace std;
class Test
{
public:
template<class T> void DoIt(int i)
{
T aT = 0;
cout << aT << " " << i << endl;
}
};
class Test2
{
public:
template<class T> void CallIt(int i)
{
Test aTest;
//THIS DOESN'T COMPILE: aTest.DoIt<T>(i);
}
void CallIt2(int i)
{
Test aTest;
aTest.DoIt<float>(i); // HERE IT COMPILES OK
}
};
int main()
{
Test2 aTest;
//aTest.CallIt(1);
aTest.CallIt2(2);
return 0;
}
//---------------------------------------------------------------
In this example, the CallIt function doesn't compile, but CallIt 2,
which uses the same syntax, but it's not a template itself, compiles
fine.
The error message I get is:
tmplt.cpp: In member function `void Test2::CallIt(int)':
tmplt.cpp:24: syntax error before `;' token
Thanks in advance!
Fernando Cuenca.
(mail to: fernando_cuenca *at* yahoo *dot* com *dot* ar)