Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with the pow( ) function [modified]

Problem with the pow( ) function [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
9 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaKa
    wrote on last edited by
    #1

    Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

    D T P C E 6 Replies Last reply
    0
    • K KaKa

      Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      KaKa` wrote:

      There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function.

      Apparently there's more than one pow() function. Which one do you want to use?


      "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

      "Judge not by the eye but by the heart." - Native American Proverb

      1 Reply Last reply
      0
      • K KaKa

        Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        how is defined the data matrix (what type) ? i think it contains values other than int, that's why the compiler doesn't know which function to call (pow(int, int) or pow(double, double) ?? ).


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        1 Reply Last reply
        0
        • K KaKa

          Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

          P Offline
          P Offline
          pgav
          wrote on last edited by
          #4

          I'm thinking that it could have something to do with your data types... are all your variables "int", or are you mixing types? Patrick

          1 Reply Last reply
          0
          • K KaKa

            Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

            C Offline
            C Offline
            cppcook
            wrote on last edited by
            #5

            If you couldn't figure out the problem, why don't you write your own pow() function? It's simple...

            Z 1 Reply Last reply
            0
            • C cppcook

              If you couldn't figure out the problem, why don't you write your own pow() function? It's simple...

              Z Offline
              Z Offline
              Zac Howland
              wrote on last edited by
              #6

              cppcook wrote:

              If you couldn't figure out the problem, why don't you write your own pow() function? It's simple...

              Simple for integer exponents ... not so simple for decimal exponents. As for the original post, my guess is that you are mixing types (that is, raising a double by an integer power). While there is nothing wrong with that, pow is usually defined: From MSDN:

              double pow(
                 double x,
                 double y 
              );
              double pow(
                 double x,
                 int y
              );  // C++ only
              double pow(
                 int x,
                 int y
              );  // C++ only
              float pow(
                 float x,
                 float y 
              );  // C++ only
              float pow(
                 float x,
                 int y
              );  // C++ only
              long double pow(
                 long double x,
                 long double y
              );  // C++ only
              long double pow(
                 long double x,
                 int y
              );  // C++ only
              float powf(
                 float x,
                 float y 
              );
              

              Try explicitly casting your types:

              double base = 3.0;
              int power = 5;
              int result = pow(base, (double)power);
              

              If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

              1 Reply Last reply
              0
              • K KaKa

                Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

                E Offline
                E Offline
                Ennis Ray Lynch Jr
                wrote on last edited by
                #7

                Is a result of implicit casts being available. Explicitly case each parameter to the datatype to use that matches one of the pow formal parameter lists. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

                1 Reply Last reply
                0
                • K KaKa

                  Hi, I am using Visual C++ 2005 to write code a win32 console application. There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function. The statement is: tempDistance += pow((data[selectedInstance][k]-data[j][k]),2); I used various headers like: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006

                  N Offline
                  N Offline
                  NrmMyth
                  wrote on last edited by
                  #8

                  If you know nothing about function overloading just cast both parameters to (double) and it will compile. tempDistance += pow(((double)data[selectedInstance][k]-data[j][k]),2.0);

                  K 1 Reply Last reply
                  0
                  • N NrmMyth

                    If you know nothing about function overloading just cast both parameters to (double) and it will compile. tempDistance += pow(((double)data[selectedInstance][k]-data[j][k]),2.0);

                    K Offline
                    K Offline
                    KaKa
                    wrote on last edited by
                    #9

                    Thanks all for the replies.......i used the simple way and cast both parameters to double and it can work now.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups