Passing a structure with multiple entries in C ++

I am trying to pass a coordinate that is defined as a structure with 2 integer parameters (the structure is called a coordinate) as follows:

UpdateB({0,0}); 

where the input argument is of type ord (i.e., in the above statement, I am trying to pass the coordinate 0,0). UpdateB- some function. I get an error, any ideas what the problem might be?

+3
source share
4 answers

Make a constructor that takes two arguments. Pass it as follows:

MyFunc(Point2d(0,0));

+7
source

. , , . , . , - ...

struct coord
{
    int x, y;

    coord(int xvalue, int yvalue)
    {
        x = xvalue;
        y = yvalue;
    }
};

... . ...

UpdateB(coord(x, y));

... x y - .

+2

, , . ++ 0x ( ) C99 ( ).
++ 03 , , .

POD, , , :

coord make_coord(int x, int y) {
    coord c = {x, y};
    return c;
}

UpdateB(make_coord(x, y));

, ,

+1
source

Radzivilovsky Paul’s decision is correct (+1).

However, you should be aware that the new standard C ++ 0x will allow the syntax of your example if you provide a constructor with two parameters (and, possibly, if you provide a constructor with a list of initializers, but this is not useful here).

This feature is already available in GCC start v4.4 , if you use it, you can enable it by enabling C ++ 0x.

0
source

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


All Articles