error C2668: ‘log’: ambiguous call to overloaded function

this post is about dealing with “ambiguous call to overloaded function” type of errors in microsoft visual studio 2008.you are welcome to add solutions to similar type of errors in comment section.

case 1 : use of math .h header to make use of log function

suppose the code fragment is similar to this one.

t=log((count[leaf]+1))/log((2));

hereĀ  after debugging the error you get is given below.

error C2668: ‘log’: ambiguous call to overloaded function

Solution:

instead of math.h header you need to use

#include <cmath>

The log function in cmath is defined as:

double log( double )
long double log( long double )
float log( float )

so you will have to typecast above codefragment as

t=log(double(count[leaf]+1))/log(double(2));


This entry was posted in Visual Studio 2008. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Torvald
    Posted February 16, 2010 at 11:33 pm | Permalink

    Thanks a lot!!!

  2. Humayun
    Posted June 29, 2011 at 3:28 pm | Permalink

    Thanks :)

  3. ws
    Posted October 11, 2011 at 6:11 am | Permalink

    Many many thankss :)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>