Ambiguous call again

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anna Smidt

    Ambiguous call again

    I am having an "ambiguous call to overloaded function" error again.

    This is the function:

    int nGetProfWidth (int ncols, unsigned ProfSpec)
    {
    if ((ProfSpec & PROF_2d) == 0)
    return ncols;
    return int(sqrt(ncols) ); //HERE THE ERROR IS THROWN
    }

    When I want to have an integer returned (as in the code above - at least
    I think it should return an integer), how should I rewrite this code?

    Anna
  • David Wilkinson

    #2
    Re: Ambiguous call again

    Anna Smidt wrote:
    I am having an "ambiguous call to overloaded function" error again.
    >
    This is the function:
    >
    int nGetProfWidth (int ncols, unsigned ProfSpec)
    {
    if ((ProfSpec & PROF_2d) == 0)
    return ncols;
    return int(sqrt(ncols) ); //HERE THE ERROR IS THROWN
    }
    >
    When I want to have an integer returned (as in the code above - at least
    I think it should return an integer), how should I rewrite this code?
    Anna:

    return int(sqrt(double (ncols)));

    You do know that most integers do not have an exact integer square root?

    --
    David Wilkinson
    Visual C++ MVP

    Comment

    • Anna Smidt

      #3
      Re: Ambiguous call again

      You do know that most integers do not have an exact integer square root?

      Thanks and...
      No, I did not know that. But I was wrong in the first place already
      anyway because I was thinking of a VB6 integer which isn't equal to
      VC++ integers as far as I know. I'm already tired enough to drop on the
      table, so I will look it up tomorrow morning (yes, I have a C++ book :-)

      Anna

      Comment

      • Anna Smidt

        #4
        Re: Ambiguous call again

        Oh, I have a question before I go to bed:

        double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );

        Why is there a space after "sqrt(" and before the last ")"?

        Comment

        • Anna Smidt

          #5
          Re: Ambiguous call again

          Okay, 1 last question:

          MatView Mat::viewAsSqua re ()
          {
          size_t ncols = size_t(sqrt(thi s->nelems()));
          // check that can square properly (assertion is not essential but
          protects the user)
          ASSERT(ncols * ncols == this->nelems());
          return MatView(*this, 0, 0, ncols, ncols, ncols);
          }

          The compiler tells me

          error C2514: 'size_t' : class has no constructors

          Why? Sorry for my many questions...
          Anna

          Comment

          • David Wilkinson

            #6
            Re: Ambiguous call again

            Anna Smidt wrote:
            >You do know that most integers do not have an exact integer square root?
            >
            Thanks and...
            No, I did not know that. But I was wrong in the first place already
            anyway because I was thinking of a VB6 integer which isn't equal to VC++
            integers as far as I know. I'm already tired enough to drop on the
            table, so I will look it up tomorrow morning (yes, I have a C++ book :-)
            Anna:

            This has nothing to do with computer languages; it's just math. What is the
            integer square root of 20? According to your formula it is 4. This may be the
            answer you want; only you know that.

            --
            David Wilkinson
            Visual C++ MVP

            Comment

            • David Wilkinson

              #7
              Re: Ambiguous call again

              Anna Smidt wrote:
              Oh, I have a question before I go to bed:
              >
              double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );
              >
              Why is there a space after "sqrt(" and before the last ")"?
              Anna:

              White space (of this kind) is ignored in C and C++ expressions.

              --
              David Wilkinson
              Visual C++ MVP

              Comment

              • David Wilkinson

                #8
                Re: Ambiguous call again

                Anna Smidt wrote:
                Okay, 1 last question:
                >
                MatView Mat::viewAsSqua re ()
                {
                size_t ncols = size_t(sqrt(thi s->nelems()));
                // check that can square properly (assertion is not essential but
                protects the user)
                ASSERT(ncols * ncols == this->nelems());
                return MatView(*this, 0, 0, ncols, ncols, ncols);
                }
                >
                The compiler tells me
                >
                error C2514: 'size_t' : class has no constructors
                Anna:

                I cannot reproduce this on VS2008. What compiler version are you using?

                --
                David Wilkinson
                Visual C++ MVP

                Comment

                • Giovanni Dicanio

                  #9
                  Re: Ambiguous call again


                  "Anna Smidt" <a.smidt@nospam gmail.comha scritto nel messaggio
                  news:%23ZPROAkN JHA.4116@TK2MSF TNGP02.phx.gbl. ..
                  Okay, 1 last question:
                  >
                  MatView Mat::viewAsSqua re ()
                  {
                  size_t ncols = size_t(sqrt(thi s->nelems()));
                  Try:

                  size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );

                  Giovanni


                  Comment

                  • Giovanni Dicanio

                    #10
                    Re: Ambiguous call again


                    "Anna Smidt" <a.smidt@nospam gmail.comha scritto nel messaggio
                    news:OVvSx9jNJH A.4428@TK2MSFTN GP04.phx.gbl...
                    Oh, I have a question before I go to bed:
                    >
                    double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );
                    >
                    Why is there a space after "sqrt(" and before the last ")"?
                    For readability of code.

                    Giovanni


                    Comment

                    • Anna Smidt

                      #11
                      Re: Ambiguous call again

                      I cannot reproduce this on VS2008. What compiler version are you using?
                      Where do I find this info?

                      Comment

                      • Anna Smidt

                        #12
                        Re: Ambiguous call again

                        Try:
                        >
                        size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );
                        >
                        Giovanni
                        This doesn't help.

                        Comment

                        • David Wilkinson

                          #13
                          Re: Ambiguous call again

                          Anna Smidt wrote:
                          >
                          >I cannot reproduce this on VS2008. What compiler version are you using?
                          >
                          Where do I find this info?
                          Anna:

                          I really meant just what version of Visual Studio are you using. If you really
                          do not know, select "About Microsoft Visual Studio" (or some such) from the Help
                          menu.

                          Could you provide a complete example illustrating this problem?

                          Something like

                          #include <math.h>

                          int main()
                          {
                          int n = 100;
                          size_t ncols = size_t(sqrt(dou ble(n)));
                          ncols; // prevent unused variable warning
                          return 0;
                          }

                          This code compiles fine for me on VS2008. Does it for you?

                          --
                          David Wilkinson
                          Visual C++ MVP

                          Comment

                          • Bo Persson

                            #14
                            Re: Ambiguous call again

                            Anna Smidt wrote:
                            Oh, I have a question before I go to bed:
                            >
                            double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );
                            >
                            Why is there a space after "sqrt(" and before the last ")"?
                            Because some people believe that it makes to code easier to read.

                            They are wrong. :-)


                            And it confuses beginners...


                            Bo Persson


                            Comment

                            • Anna Smidt

                              #15
                              Re: Ambiguous call again

                              Because some people believe that it makes to code easier to read.
                              They are wrong. :-)
                              And it confuses beginners...
                              Agreed :-)

                              Comment

                              Working...