jDOG
jDOG

Reputation: 1201

Header inclusion and compiler errors

In my CPP file I have a call that is:

pt.x = mDownPoint.x + FSign(pt.x-mDownPoint.x) *
        FMax( FAbs(pt.x-mDownPoint.x), FAbs(pt.y-mDownPoint.y) );

I get compiler errors for FSign, FMax, FAbs, but I include the header file where they are at.

So I don't see why it would not find it, unless I have done something wrong in the creation of this header file.

Can I get some pointers on what I am doing wrong?

Header:

class FxMathFunctions
{
struct FxPoint2d;

public:
    FxMathFunctions();
    ~FxMathFunctions();

    static FxInt32 IMin(FxInt32 i1,FxInt32 i2);
    static FxInt32 IMax(FxInt32 i1,FxInt32 i2);
    static FxInt32 ILimit(FxInt32 val, FxInt32 i1, FxInt32 i2);
    static FxDouble FMin(FxDouble i1,FxDouble i2);
    static FxDouble FMax(FxDouble i1,FxDouble i2);
    static FxFloat FMax(FxFloat i1,FxFloat i2);
    static FxFloat FLimit(FxFloat val, FxFloat i1, FxFloat i2);
    static FxDouble FrInverseContrast(FxDouble opacity,FxDouble antialias);
    static FxInt32 ISign(FxInt32 l);
    static FxFloat FSign(FxFloat v);
    static FxInt32 IAbs(FxInt32 l);
    static FxFloat FAbs(FxFloat v);
    static FxInt32 INonzero(FxInt32 l);
    static double DAbs(double v);
    static FxInt32 Sqr(FxByte v);
    static FxInt32 Sqr(FxInt32 v);
    static FxFloat Sqr(FxFloat v);
    static FxDouble Sqr(FxDouble v);
    static FxInt32 FrCubed(FxByte v);
    static FxInt32 FrCubed(FxInt32 v);
    static FxFloat FrCubed(FxFloat v);
    static FxDouble FrCubed(FxDouble v);
    static FxDouble FrFourthPower(FxDouble v);
    static FxFloat FrFourthPower(FxFloat v);
    static FxBool FNearEqual(FxFloat val, FxFloat nearTo, FxFloat closeness = 0.00001f);
    static FxBool FNearGreaterEqual(FxFloat val, FxFloat nearTo, FxFloat closeness = 0.00001f);
    static FxBool FNearLessEqual(FxFloat val, FxFloat nearTo, FxFloat closeness = 0.00001f);
};

.CPP to Header where applicable for one function that is failing:

FxFloat FAbs(FxFloat v)
{
    if (v < 0.0f) v = -v;
    return v;
}

EDIT:

Fixed call:

pt.x = mDownPoint.x + FxMathFunctions::FSign(pt.x-mDownPoint.x) * 
                FxMathFunctions::FMax( FxMathFunctions::FAbs(pt.x-mDownPoint.x),
                FxMathFunctions::FAbs(pt.y-mDownPoint.y) );

Failing with:

error: cannot call member function 'FxFloat FxMathFunctions::FAbs(FxFloat)'

Upvotes: 0

Views: 180

Answers (1)

GManNickG
GManNickG

Reputation: 503755

All the function are within FxMathFunctions, so it should be:

pt.x = mDownPoint.x + FxMathFunctions::FSign(pt.x-mDownPoint.x) *
        FxMathFunctions::FMax( FxMathFunctions::FAbs(pt.x-mDownPoint.x), 
        FxMathFunctions::FAbs(pt.y-mDownPoint.y) );

But this is what namespaces are for, I don't think you actually want a class. If it's a namespace, you can even do using namespace FxMathFunctions; at the top of the function your code is in and leave the code you have in the question.


Secondly, a lot of those functions don't need to be written, unless you've gotten some hand-written implementation of them. (Just use cmath and utility, for things like std::fabs and std::min.) Lastly, why not overload FAbs and DAbs to just Abs, like you do for Sqr? It would make the interface simpler.

Upvotes: 1

Related Questions