What does the construct keyword do when adding a method?

The code here is X ++. I know very little about this, although I am familiar with C #. MS says it looks like C ++ and C # syntax.

In any case, I assume that the code below is a method. It has "Construct" as a keyword.

What is the construct / Constructor method? What will the construct keyword change when applied to this function? Also, am I mistaken in assuming the code will create some kind of infinite loop?

My guess is that this is a method with a return type of "InventMovement".

static InventMovement construct(Common buffer, InventMovSubType subType = InventMovSubType::None, Common childBuffer = null)
{
    InventMovement movement = InventMovement::constructNoThrow(buffer,subType,childBuffer);

    if (!movement)
        throw error("@SYS20765");

    return movement;
}

Thanks! Kevin

+3
source share
3 answers

- X ++, construct, InventMovement. , . AX Factory. , AX , .

InventMovement , InventMov_Purch InventMov_Sales. new() , , switch new InventMov_Purch(), new InventMov_Sales() , InventMovement, InventMovement::construct() ().

+8

X ++ construct. - , Factory X ++. "construct" () , - ( ) . construct . .

X ++ (rougly) ++:

class Base
{
public:
    static Base * construct(int aType);
    //some instance methods here
}; 

class Concrete1 : public Base
{
    // concrete implementation 1
};

class Concrete2 : public Base
{
    // concrete implementation 2
};

Base * Base::construct(int aType)
{
    switch(aType)
    {
        case 1:
            return  (Base*) new Concrete1();
        case 2:
            return (Base*) new Concreate2();
    }
}
0

: X ++.

, , construct .

++

static Foo::Foo(int arg1) { this->val = arg1 }

, - X ++ construct . , constructNoThrow, , , .

-1

Source: https://habr.com/ru/post/1711357/


All Articles