|
I strive writing articles for the masses.
I have observed new professionals do want to know "WHY" and "WHEN", instead of "HOW" and "WHAT". My Multithreading articles follow the same - they explain When/Why in simple and understandable manner, with less of 'How' coverage that gives only syntax and reference material.
I put this message just to know what you guys need to know something better, more clear and more exhaustive. Though my primary domain is C++ area, I won't bother writing on other aspects if it suites me!
|
|
|
|
|
Message Closed
modified 4-Aug-15 7:44am.
|
|
|
|
|
Congrats Ajay for MVP. Well deserved
|
|
|
|
|
Might be late... Congrats for been MVP
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi Ajay,
I just started reading your article and i got confused.As per my understanding after reading starting of your article.i got some doubts.Eg:
template<class t="">
T max(T t1, T t2)
{
if (t1 > t2)
return t1;
return t2;
}
int main(){
std::cout<<max<int>120,14.55);//=>you have explained like here if i explicitly mention one data type,other would be deducted from the argument type(14.55) by the compiler.That means T max(T t1, T t2)becomes T max(int t1,double t2).But when i compiled it i got the below warning
warning: passing double for argument 2 to T max(T, T) [with T = int].Then why this warning came is my question.
also since we are using only T,if i mention max<int>,then T max(T t1, T t2) should be like this int max(int t1, int t2) na??
return 0;
}
Please clear my doubts.else i cant proceed further
|
|
|
|
|
Hi Ajay,
I just started reading your article and i got confused.As per my understanding after reading starting of your article.i got some doubts.Eg:
template<class T>
T max(T t1, T t2)
{
if (t1 > t2)
return t1;
return t2;
}
int main(){
std::cout<<max<int>120,14.55);//=>you have explained like here if i explicitly mention one data type,other would be deducted from the argument type(14.55) by the compiler.That means T max(T t1, T t2)becomes T max(int t1,double t2).But when i compiled it i got the below warning
warning: passing double for argument 2 to T max(T, T) [with T = int].Then why this warning came is my question.
also since we are using only T,if i mention max<int>,then T max(T t1, T t2) should be like this int max(int t1, int t2) na??
return 0;
}
Please clear my doubts.else i cant proceed further
Subi Suresh
|
|
|
|
|
You did read or understood it wrong!
For T max(T t1, T t2) , the template type argument is just one - T .
If you call it like:
max(10,20.0);
You will get a compiler error for ambiguity. So, you can explicitly specify the type:
max<double>(10,20.0); . If you specify <int> as type, you will get warning.
Two things:
* Please read, understand, code, experiment very well before rushing to ask question. There is nothing wrong in asking question - but you will learn MORE if you attempt to get it yourself!
* Please do reply/comment on the Article page itself, and not on profile page (for any author). This will help fellow readers to get answers.
|
|
|
|
|