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. 'sqrt' : undeclared identifier

'sqrt' : undeclared identifier

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
10 Posts 5 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.
  • R Offline
    R Offline
    rbc
    wrote on last edited by
    #1

    Why is that Visual C++'s GUI knows about sqrt yet the compiler doesn't? :confused: As I edit my source I typed in sqrt and as I start to type in the paramters the GUI presents me with 3 different prototypes of sqrt ... I think cool Visual C++ knows about sqrt ... so I typed sqrt( myDouble ); as per the GUI. Yet I get a compiler error? X|

    C 1 Reply Last reply
    0
    • R rbc

      Why is that Visual C++'s GUI knows about sqrt yet the compiler doesn't? :confused: As I edit my source I typed in sqrt and as I start to type in the paramters the GUI presents me with 3 different prototypes of sqrt ... I think cool Visual C++ knows about sqrt ... so I typed sqrt( myDouble ); as per the GUI. Yet I get a compiler error? X|

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Because the IDE searchs all the headers in the include paths, but the compiler requires that you include them. It's probably math.h, or cmath ( which, if it works, is preferred ). Also cmath may require you use std::sqrt. All of this is a guess, but I am pretty sure that math.h at least will be the right one, and it's certainly a missing #include. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
      C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
      Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

      R 1 Reply Last reply
      0
      • C Christian Graus

        Because the IDE searchs all the headers in the include paths, but the compiler requires that you include them. It's probably math.h, or cmath ( which, if it works, is preferred ). Also cmath may require you use std::sqrt. All of this is a guess, but I am pretty sure that math.h at least will be the right one, and it's certainly a missing #include. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
        C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
        Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

        R Offline
        R Offline
        rbc
        wrote on last edited by
        #3

        My code looks kinda like this ...

        #include "math.h"
        #include "stdafx.h"
        .
        .
        .
        double BlahBlah::Blah_Abs ( double real, double img ) {
        double rc = real * real + img * img;
        return sqrt( rc );
        }
        .
        .
        .

        Yet the compiler does not complain about not be able to find math.h in the include path so I must assume that VC++ knows about math.h and since the compiler errors on sqrt ( rc ); I guess that sqrt( double ) is not declared in math.h :confused:

        K RaviBeeR C 3 Replies Last reply
        0
        • R rbc

          My code looks kinda like this ...

          #include "math.h"
          #include "stdafx.h"
          .
          .
          .
          double BlahBlah::Blah_Abs ( double real, double img ) {
          double rc = real * real + img * img;
          return sqrt( rc );
          }
          .
          .
          .

          Yet the compiler does not complain about not be able to find math.h in the include path so I must assume that VC++ knows about math.h and since the compiler errors on sqrt ( rc ); I guess that sqrt( double ) is not declared in math.h :confused:

          K Offline
          K Offline
          kjessee
          wrote on last edited by
          #4

          include the math.h file I bet it will work. Kevin

          1 Reply Last reply
          0
          • R rbc

            My code looks kinda like this ...

            #include "math.h"
            #include "stdafx.h"
            .
            .
            .
            double BlahBlah::Blah_Abs ( double real, double img ) {
            double rc = real * real + img * img;
            return sqrt( rc );
            }
            .
            .
            .

            Yet the compiler does not complain about not be able to find math.h in the include path so I must assume that VC++ knows about math.h and since the compiler errors on sqrt ( rc ); I guess that sqrt( double ) is not declared in math.h :confused:

            RaviBeeR Offline
            RaviBeeR Offline
            RaviBee
            wrote on last edited by
            #5

            sqrt requires #include <math.h> /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

            1 Reply Last reply
            0
            • R rbc

              My code looks kinda like this ...

              #include "math.h"
              #include "stdafx.h"
              .
              .
              .
              double BlahBlah::Blah_Abs ( double real, double img ) {
              double rc = real * real + img * img;
              return sqrt( rc );
              }
              .
              .
              .

              Yet the compiler does not complain about not be able to find math.h in the include path so I must assume that VC++ knows about math.h and since the compiler errors on sqrt ( rc ); I guess that sqrt( double ) is not declared in math.h :confused:

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Just to reiterate and add my voice to the cacophany, the intellisense parses all include paths, but the compiler will only compile if you actually include the bits you need in your code. I suggest that it's a wise course of action when people answer your question to try the suggested solution before arguing about it. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
              C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
              Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

              R 1 Reply Last reply
              0
              • C Christian Graus

                Just to reiterate and add my voice to the cacophany, the intellisense parses all include paths, but the compiler will only compile if you actually include the bits you need in your code. I suggest that it's a wise course of action when people answer your question to try the suggested solution before arguing about it. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                R Offline
                R Offline
                rbc
                wrote on last edited by
                #7

                I am including math.h but codeproject thinks le math.h ge is somekind of HTML tag! X| And WTF is this ... I suggest that it's a wise course of action when people answer your question to try the suggested solution before arguing about it. ... about? I am not arguing about anything :omg:

                C 1 Reply Last reply
                0
                • R rbc

                  I am including math.h but codeproject thinks le math.h ge is somekind of HTML tag! X| And WTF is this ... I suggest that it's a wise course of action when people answer your question to try the suggested solution before arguing about it. ... about? I am not arguing about anything :omg:

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  My apologies - you didn't check the 'display message as is' option, nor did you use the buttons above the emoticons which would replace a < with a < and so on, making it show OK. As a result I presumed you were saying what you said in the first place, as did all the other people who replied. I see you have edited the code now :0)

                  #include "math.h"
                  #include "stdafx.h"

                  Anything before stdafx.h is ignored. Move it down and it will work. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                  C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                  Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                  N R 2 Replies Last reply
                  0
                  • C Christian Graus

                    My apologies - you didn't check the 'display message as is' option, nor did you use the buttons above the emoticons which would replace a < with a < and so on, making it show OK. As a result I presumed you were saying what you said in the first place, as did all the other people who replied. I see you have edited the code now :0)

                    #include "math.h"
                    #include "stdafx.h"

                    Anything before stdafx.h is ignored. Move it down and it will work. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                    C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                    Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #9

                    Christian Graus wrote: Anything before stdafx.h is ignored. Move it down and it will work. As noted on page 216 of Programming Windows with MFC. ;P I knew I had read that before and I had to look it up.


                    Nick Parker

                    You see the Standards change. - Fellow co-worker

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      My apologies - you didn't check the 'display message as is' option, nor did you use the buttons above the emoticons which would replace a < with a < and so on, making it show OK. As a result I presumed you were saying what you said in the first place, as did all the other people who replied. I see you have edited the code now :0)

                      #include "math.h"
                      #include "stdafx.h"

                      Anything before stdafx.h is ignored. Move it down and it will work. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                      C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                      Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                      R Offline
                      R Offline
                      rbc
                      wrote on last edited by
                      #10

                      DOH!:-O Thanks!

                      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