Jul.01.2018 -- CAlive to introduce mated constructor/destructor pairs

7 views
Skip to first unread message

Rick C. Hodgin

unread,
Jul 1, 2018, 9:04:50 PM7/1/18
to CAlive Programming Language
CAlive will introduce mated constructor and destructor pairs allowing class instances to receive a custom destructor, with the ability to call the default() constructor as needed.

    class CExample
    {
    public:
        CExample(int a)
        {
            // constructor code here
            printf("int constructor\n");

        } ~ {
            // mated destructor code here
            default();
            printf("Mated destructor\n");
        }

        CExample(s8* tcText)
        {
            // constructor code here
            printf("s8* constructor\n");

        } ~ {
            // mated destructor code here
            printf("Mated destructor\n");
            default();
        }

        CExample(f32 f)
        {
            // constructor code here
            printf("f32 constructor\n");

        } ~ {
            // mated destructor code here
            printf("f32 destructor\n");
        }

        // Normal destructor
        ~CExample()
        {
            printf("Destructor\n");
        }
    };

    function main
    | params int argc, char* argv[]
    | returns int r
    {
        CExample e1(5);
        CExample e2("Hello");
        CExample e3(1.2f);

        printf("\n");

        r = 0;
    }

The output of the above program would be:

    int constructor
    s8* constructor
    f32 constructor

    int destructor
    int mated destructor
    s8* mated destructor
    s8* destructor
    f32 mated destructor

-- 
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages