views:

54

answers:

1

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)'

+1  A: 

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.

GMan
@GMan - so I think my confusion here is scope. When you include header files and use functions in header files you should always do SCOPE::FUNCTION? This seems new to me, this whole project from 1998 that is being updated has never done this. Codewarrior to XCode. Do you have core, no bull-shit, no fluff C++ reference? I just bought the C++ Programming Language yesterday by Stroustrup.
jDOG
@jDOG: Those functions are static members of a class. You can't drop the classname. I guess that would be a reason why it would make more sense to put those functions in a namespace instead...
UncleBens
@jDOG: Well I have the standard which is as core, no bull-shit, no fluff as it gets, but I don't think that's quite what you wanted. :) We have a [book list](http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list). And yes, declarations have scope, and those functions are within a scope. So to call them, you need to resolve the scope with the scope name (`FxMathFunctions`) and scope resolution operator (`::`), aka: `FxMathFunctions::FAbs`. And it should really be changed into a namespace, since that's all the class-name is acting like.
GMan
@Gman - good point about overloading, I will do that. These functions are very custom unfortunately. The guy who wrote these had zero programming skills, but a very good math mind.
jDOG
@GMan - are there performance benefits for changing to using namespaces verses SCOPE::FUNCTION?
jDOG
@jDOG: That's alright. No, names have nothing to do with runtime, scope is a compile-time concept. There's just a design-improvement and usability improvement.
GMan
@GMan - Another related question when I add FxMathFunctions::FAbs, etc I get an error that states: error: cannot call member function 'FxFloat FxMathFunctions::FAbs(FxFloat)' without object I thought that since these functions were static that this would be OK, do I have to instantitate an object and act on it? FXMathFunctions f; f.FAbs...etc etc?
jDOG
@jDOG: No, if it's static it should work. Is the code in your question the exact code? What compiler? Edit these details into your question and I'll edit in a response.
GMan
@GMan - everything is provided above. XCode 3.2.3, GCC 4.2 against the 10.4u SDK.
jDOG
@jDOG: Well, if it's marked static you don't need an instance. I noticed the cpp seems to be wrong, it shouldn't be `FxFloat FAbs(FxFloat v)` but `FxFloat FxMathFunctions::FAbs(FxFloat v)`. (Of course, a namespace has no problem. :) )
GMan