How to declare structure? [Solved]

Правка en6, от ivanz, 2021-05-20 19:45:07

I have two structures declared this way:

struct dot {                                                                                            
    int x, y;                                                                                            
};                                                                                            
                                                                                            
                                                                                            
struct pig : dot {                                                                                            
    int z;                                                                                            
}; 

I can declare dot variable like this:

dot a = {1, 100};

But how can I declare pig variable? The only way I found is this:

pig b;                                                                                            
b.x = 1;                                                                                            
b.y = 100;                                                                                            
b.z = 2134;    

Is there any way to do it easier, like with dot variables?
I tried this:

pig b = {1, 100, 2133}

but it doesn't work.
Please, help!

Here's what I was looking for:

struct dot {
    int x, y;
};


struct pig : dot {
    int z;

    pig(int x_, int y_, int z_) : dot{x_, y_}, z{z_} {}
};


pig b{1, 2, 3};

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский ivanz 2021-05-20 19:45:07 219
en5 Английский ivanz 2021-05-20 19:39:06 3 Tiny change: ' \n} \n~~~~~\n' -> ' \n}; \n~~~~~\n'
en4 Английский ivanz 2021-05-20 14:57:17 2 Tiny change: '\n int a; ' -> '\n int z; '
en3 Английский ivanz 2021-05-20 14:47:36 66
en2 Английский ivanz 2021-05-20 14:46:34 390
en1 Английский ivanz 2021-05-20 14:45:13 1643 Initial revision (published)