2

It's my first post here, I have looked for an answer for days, so I have ask. It is a complex construction. I embed SpiderMonkey javascript engine in an Illustrator plugin. Illustrator has a complicate and sometimes inconsistent API. In this case I have to call a method having a short type as parameter:

namespace ai
{
...
typedef signed short    int16;
...
};

The method is referred as a pointer in a struct:

struct AIDocumentSuite {
...
    AIAPI AIErr (*GetDocumentRulerUnits) ( ai::int16 *units );
...
};

But, an enum is the source of the parameter:

enum AIDocumentRulerUnitValue {
    kUnknownUnits = 0,
    /** inches */
    kInchesUnits,
    /** centimeters */
    kCentimetersUnits,
    /** points */
    kPointsUnits,
    /** picas */
    kPicasUnits,
    /** millimeters */
    kMillimetersUnits,
    /** pixels */
    kPixelsUnits,
    /** Q units */
    kQUnits
};

I have wrapped all these in classes in order to have javascript objects managed by SpiderMonkey. I have the following working call somewhere in the code (a bit simplified, cleaned up of tests an verifications):

ai::int16 aiDocumentRulerUnitValue;
AIErr aiErr = sAIDocument->GetDocumentRulerUnits(&aiDocumentRulerUnitValue);

...

            if (!jsAIDocumentRulerUnitValue::FromAIObject<jsAIDocumentRulerUnitValue>(cx, &aiDocumentRulerUnitValue, value))
                return false;

...
            jsProperty::SetProperty(cx, &obj, "value", value, true);

...

My issue is FromAIObject.

I have a template base class:

template<typename T> class jsBaseDataClass : public jsBaseClass
{
public:
...

    template <typename jsT> static bool FromAIObject(JSContext *cx, T* aiObj, JSObject*& obj)
    {
...
return true;
    }
}

and a derived class:

class jsAIDocumentRulerUnitValue : public jsBaseDataClass<AIDocumentRulerUnitValue>
{
public:
...
    template <typename jsT> static bool FromAIObject(JSContext *cx, ai::int16* aiint16, JSObject*& obj)
    {
        AIDocumentRulerUnitValue aiDocumentRulerUnitValue = static_cast<AIDocumentRulerUnitValue>(*aiint16);

        return jsEnumDataClass<jsBaseClass>::FromAIObject<jsAIDocumentRulerUnitValue>(cx, &aiDocumentRulerUnitValue, obj);
    }

...
}

Now, the issue: if I write in the latter one:

jsAIDocumentRulerUnitValue::FromAIObject<jsAIDocumentRulerUnitValue>(cx, &aiDocumentRulerUnitValue, obj);

it will try to call the method in the derived class (with the parameter of type ai::int16 = signed short).

If the method in the derived class wouldn't exist, it will call the method from the parent class, regardless the type of the second parameter.

I wish to be able to look for the suitable method based on its parameters. This would make me having a copy in each derived class of both methods (if necessary, or at least a copy of the default one).

What am I doing wrong or how could I make them behave as in non static method overloading with inheritance?

Thank you.

2
  • Read some theory about virtual functions and function overriding in c++ and then ask. Commented Jan 16, 2016 at 8:57
  • Sorry, I'm bound to statics, where virtuals are not applicble, AFAIK... Commented Jan 16, 2016 at 9:23

2 Answers 2

1

Do something like that.

class Base {
public:
    static void method(std::string someParam);
}

class Derived : public Base {
public:
    using Base::method;
    static void method(int param);
}

The point is using the using keyword for making base class's functions visible.

Sign up to request clarification or add additional context in comments.

Comments

0

You are doing nothing wrong. Your question looks like a duplicate of stack overflow: inheritance and method overloading

Overloaded methods get lost unless you using XXXX

2 Comments

Well, I've seen that, but there were not static methods, so I've presumed it might be something different.
I'm a bit rusty in C++, I did not ever use using. Could you please point me how could I implement with it here? Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.