Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: template er...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 45888 of 47017
Post > Topic >>

Re: template error with iterator

by utab <umut.tabak@[EMAIL PROTECTED] > May 12, 2008 at 04:51 PM

On May 13, 1:47 am, tragomaskhalos <dave.du.verg...@[EMAIL PROTECTED]
>
wrote:
> On 13 May, 00:37, utab <umut.ta...@[EMAIL PROTECTED]
> wrote:
>
>
>
>
>
> > template <class T, class Ran>
> > T median(Ran b, Ran e)
> > {
> >   typedef typename vector<T>::size_type vec_sz;
>
> >   vec_sz size = (e-b)/sizeof(T);
> >   if (size == 0)
> >     throw domain_error("median of an empty vector");
>
> >   sort(b, e);
>
> >   vec_sz mid = size/2;
>
> >   return size % 2 == 0 ? (b[mid] + b[mid-1]) / 2 : b[mid];
>
> > }
>
> > int main()
> > {
> >   vector<double> vec;
> >   for(int i=0;i!=10;++i)
> >     vec.push_back(i);
> >   std::cout << median(vec.begin(), vec.end()) << std::endl;
>
> The compiler cannot deduce T; replace the above call with
> median<double>(vec.begin(), vec.end())
>        ^^^^^^
>
> >   return 0;
>
> > }

Thanks, I read something similar in the faq as well.
 




 8 Posts in Topic:
template error with iterator
utab <umut.tabak@[EMAI  2008-05-12 16:37:07 
Re: template error with iterator
utab <umut.tabak@[EMAI  2008-05-12 16:40:04 
Re: template error with iterator
tragomaskhalos <dave.d  2008-05-12 16:47:35 
Re: template error with iterator
utab <umut.tabak@[EMAI  2008-05-12 16:51:26 
Re: template error with iterator
acehreli@[EMAIL PROTECTED  2008-05-12 16:52:42 
Re: template error with iterator
Paavo Helde <nobody@[E  2008-05-12 18:57:09 
Re: template error with iterator
Greg Herlihy <greghe@[  2008-05-12 16:58:41 
Re: template error with iterator
James Kanze <james.kan  2008-05-13 02:26:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:08:48 CDT 2008.