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 2 1233
sarathy wrote:
Hi all,
I have a clarification in C++ Templates.
You have it? Or do you *need* it?
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"
I don't see this statement on the page you gave.
ie real_test (10,20,30) will do instead of real_test
<int,int,int>(10,20,30);
Yes.
ie real_test("Hello",123,34.56); wont work instead of real_test<const
char*, int, double("Hello",123,34.56);
It will. Your template *arguments* are all independent types. They
will all be deduced independently.
Please clarify whether the statement in the URL is correct.
Again, I don't see that statement in "the URL".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apology. I got it in the wrong sense from the URL. Clear now.
Thanx & Rgrds,
Sarathy
Victor Bazarov wrote:
sarathy wrote:
Hi all,
I have a clarification in C++ Templates.
You have it? Or do you *need* it?
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"
I don't see this statement on the page you gave.
ie real_test (10,20,30) will do instead of real_test
<int,int,int>(10,20,30);
Yes.
ie real_test("Hello",123,34.56); wont work instead of real_test<const
char*, int, double("Hello",123,34.56);
It will. Your template *arguments* are all independent types. They
will all be deduced independently.
Please clarify whether the statement in the URL is correct.
Again, I don't see that statement in "the URL".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Karthik D |
last post by:
Hello All,
I am a newbie to C++ code particularly templates.Below is a
template class defintion and I couldn't find the ObjPtr/ObjFnPtr class
definition anywhere in source code.
template<class...
|
by: Tom Alsberg |
last post by:
Hi there...
I'm recently trying to get a bit acquainted with XML Schemas and XSL.
Now, I have a few questions about XSL stylesheets and templates:
* Is there a way to "enter" a child element...
|
by: E. Robert Tisdale |
last post by:
According to the C++ FAQ Lite:
http://www.parashift.com/
What is "genericity"?
Yet another way to say, "class templates."
Not to be confused with "generality"
(which just means avoiding...
|
by: Rakesh |
last post by:
Hi,
I was writing this C++ program wherein I used an include statement
like -
#include <iostream.h>
I was told by my co-worker that this form of including a file is
deprecated and should...
|
by: WittyGuy |
last post by:
Hi,
What is the major difference between function overloading and function
templates?
Thanks!
http://www.gotw.ca/resources/clcm.htm for info about ]
|
by: Frankie Montenegro |
last post by:
Hi everyone,
I must say that, even though I think
that Accelerated C++ by Koenig and Moo is an awesome
text, the wording of exercises is very poor. I
spend half the time just trying to figure...
|
by: Sai Kit Tong |
last post by:
In the article, the description for
"Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports
or
Managed Entry Points"
suggests the creation of the class ManagedWrapper.
If I...
|
by: Ted |
last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because
they were rejected in comp.lang.c++.moderated. It behooves anyone reading
them to first read the the thread of the...
|
by: NewToCPP |
last post by:
Hi,
I am just trying to find out if there is any strong reason for not
using Templates. When we use Templates it is going to replicate the
code for different data types, thus increasing the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |