MESSAGE
DATE | 2011-05-24 |
FROM | Ruben Safir
|
SUBJECT | Re: [NYLXS - HANGOUT] [ruben@mrbrklyn.com: Re:
|
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Victor Bazarov Newsgroups: comp.lang.c++ Subject: Re: Template argument determination Date: Tue, 24 May 2011 11:43:26 -0400 Organization: A noiseless patient Spider Lines: 49 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 24 May 2011 15:43:27 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mfoyPVXLF0MtM1ZkAsRgyQ"; logging-data="31217"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX1/C7I8P09Pb9rAZBZkqJC1eaXCrnxP8Yw0=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:xwmh1LRs4qzK91MZjldtaTdR8fE= Xref: panix comp.lang.c++:1085263
On 5/24/2011 11:04 AM, Ruben Safir wrote: > Lets look at it this way > > why does this fail to compile > > template > void test_me(stats::Distribution hello){ > std::cout<< "I recied an int and converted it to an object "<< > hello<< std::endl; > } > > > > int main ( int argc, char *argv[] ){ > int a = 7; > test_me(a); > > return EXIT_SUCCESS; > }
You ask the compiler to find what 'T' would be. During template argument deduction the compiler does NOT use any potential promotions or conversions. The fact that 'stats::Distribution' has a conversion from 'int' has *no importance* to the template argument deduction process.
> > > yet this does, with the promotion of the int to a distribution object > > > template > void test_me(stats::Distribution hello){ > std::cout<< "I received an int and converted it to an object "<< > hello<< std::endl; > } > > > int main ( int argc, char *argv[] ){ > int a = 7; > test_me(a);
Here no template argument deduction is necessary since you supplied the argument.
> > return EXIT_SUCCESS; > }
V -- I do not respond to top-posted replies, please don't ask
|
|