Can't compile overloaded class operator wth TNT include

Discussion in 'Mac Programming' started by ScKaSx, Sep 27, 2007.

  1. ScKaSx macrumors regular

    Joined:
    Feb 27, 2006
    #1
    Hi All,

    I am trying to use the TNT (template numerical toolkit) include files in some of my C++ code. In one of the files the class operator 'sign' is overloaded:

    "inline double sign(double a)
    {
    return (a > 0 ? 1.0 : -1.0);
    }

    inline float sign(float a)
    {
    return (a > 0.0 ? 1.0f : -1.0f);
    }
    "

    When I try to use this include my compiler (g++ from command line) gives the following error:

    "
    /usr/include/tnt/tntmath.h: In function 'float TNT::sign(float)':
    /usr/include/tnt/tntmath.h:65: error: declaration of C function 'float TNT::sign(float)' conflicts with
    /usr/include/tnt/tntmath.h:58: error: previous declaration 'double TNT::sign(double)' here
    "

    Any ideas?

    Thanks,
    ScKaSx
     
  2. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    I think the file in which you are including this is being compiled with the C compiler, not the C++ compiler.
     
  3. ScKaSx thread starter macrumors regular

    Joined:
    Feb 27, 2006
    #3
    iSee, thanks for the response. So I moved the tnt files to the local directory of my program and don't have that problem anymore (not that all of my problems are solved, however).

    To get this straight, does that mean g++ doesn't look in the same path as gcc? And if this is the case, how can I configure g++ as to where to look for include files?

    Cheesrs
     
  4. thealtered7 macrumors newbie

    Joined:
    Sep 11, 2007
    Location:
    Denver
    #4
    You can pass directories to g++ when compiling from the command line. I can't recall the exact option to specify, read the man pages.
    Else, you could put the libraries you are using directly within the c++ include folder buried deep within the Developer directory.
     

Share This Page