Namespace std in cmath



  • I am studying C++ GUI Programming with Qt 4.1 1st edition and have a question. The plotter widgets implementation file (p.119) starts with:

    @
    #include <QtGui>
    #include <cmath>
    #include "plotter.h"
    @

    A text follows these 3 lines:

    "We include the expected header files and import all the std namespace’s
    symbols into the global namespace. This allows us to access the functions that
    are declared in <cmath> without prefixing them with std:: (for example, floor()
    instead of std::floor())."

    My personal experience is that a line similar to

    @ using namespace std; @

    is used for this purpose, which I can not find.

    So my question is: Where that namespace command is hidden? and why?



  • [quote author="simplePlan" date="1345356433"]
    So my question is: Where that namespace command is hidden? and why?
    [/quote]

    Maybe you should ask the author that? The book is not open source...

    Anyhow, yes, the line using namespace std; is needed for the described behaviour. Is it in plotter.h?

    PS: use qmath.h and then qFloor, qExp, qLn, qSin,...



  • It is not in 'plotter.h'. 1st edition is under Open Publication License available at http://www.qtrac.eu/marksummerfield.html (book #7).

    I also checked the find-routine in my pdf reader. No 'using namespace std' directive somewhere. I usually use the qLibraries when available, but that is an example and I want to stick to the authors code as much as i can.



  • [quote author="simplePlan" date="1345373831"]It is not in 'plotter.h'. 1st edition is under Open Publication License available at http://www.qtrac.eu/marksummerfield.html (book #7).[/quote] Nice, I didn't known that!

    [quote]I also checked the find-routine in my pdf reader. No 'using namespace std' directive somewhere.[/quote]
    I guess he then either just didn't include it in the text for brevity or just forgot it. Don't worry about it too much ;)



  • It is a pretty good book. Everything is explained very carefully and without any gaps. That is why I was wondering. But it is of course a minor issue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.