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

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; }

Replies are listed 'Best First'.
Re^5: returning an object in XS
by BrowserUk (Patriarch) on Feb 29, 2012 at 19:18 UTC
      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.
        I am sorry I couldn't answer your question like he does.

        NP. This is one reason why I dislike the general resistance to off-topic (but related) subjects here. There are always several someones watching that know the answer. (ikegami tends to be about half of those someones:)


        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?