in reply to Re^2: returning an object in XS
in thread returning an object in XS

It's C++,

It still doesn't look like any syntax I'm familiar with? It's been a while since I did any serious C++, but even so?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^4: returning an object in XS
by ikegami (Patriarch) on Feb 29, 2012 at 18:55 UTC

    It's a variable declaration with an initialiser.

    $ cat a.cpp #include <stdio.h> struct Point { Point(int a_x, int a_y) : x(a_x), y(a_y) {} int x; int y; }; int main() { Point point(5,6); printf("%d,%d\n", point.x, point.y); return 0; } $ g++ -o a a.cpp && a 5,6

    It's like new, but the object is allocated on the stack instead of the heap, and the variable is a reference instead of a pointer. It's the object equivalent of

    int i = 5;

    which can also be written as

    int i(5);

    which is what allowed me to write

    Point(int a_x, int a_y) : x(a_x), y(a_y) {}

    instead of

    Point(int a_x, int a_y) { x = a_x; y = a_y; }
        I would like to thanks Ikegami for his answer. I am just a beginner myself on C/C++. I am sorry I couldn't answer your question like he does.