S
sarathy
Hi all,
I have a clarification in C++ Templates.
Consider that we have created a template as below
template <class T1,class T2, class T3>
void real_test(T1 a, T2 b ,T3 c)
{
const char *x=a;
int y=b;
double z=c;
cout << x << " " << y << " " << z << endl;
}
when this method is called from main, there are 2 ways of calling it.
real_test<const char*, int, double> ("Hello",123,34.56);
real_test("Hello",123,34.56);
Both worked fine in gcc-3.2.2 in Redhat9 i386.
But when i read the document at the following URL
http://www.cplusplus.com/doc/tutorial/templates.html
it read as
"Only when all the values passed to the template, are of the same type,
then compiler will automatically detect the type, else it wont and it
will generate an error"
ie real_test (10,20,30) will do instead of real_test
<int,int,int>(10,20,30);
ie real_test("Hello",123,34.56); wont work instead of real_test<const
char*, int, double> ("Hello",123,34.56);
Please clarify whether the statement in the URL is correct.
Regards,
Sarathy
I have a clarification in C++ Templates.
Consider that we have created a template as below
template <class T1,class T2, class T3>
void real_test(T1 a, T2 b ,T3 c)
{
const char *x=a;
int y=b;
double z=c;
cout << x << " " << y << " " << z << endl;
}
when this method is called from main, there are 2 ways of calling it.
real_test<const char*, int, double> ("Hello",123,34.56);
real_test("Hello",123,34.56);
Both worked fine in gcc-3.2.2 in Redhat9 i386.
But when i read the document at the following URL
http://www.cplusplus.com/doc/tutorial/templates.html
it read as
"Only when all the values passed to the template, are of the same type,
then compiler will automatically detect the type, else it wont and it
will generate an error"
ie real_test (10,20,30) will do instead of real_test
<int,int,int>(10,20,30);
ie real_test("Hello",123,34.56); wont work instead of real_test<const
char*, int, double> ("Hello",123,34.56);
Please clarify whether the statement in the URL is correct.
Regards,
Sarathy