If my initialization of variables in the .h in the constructor occurs by default, do I need to initialize them again in the .cpp file? For example:

 // .h Ρ„Π°ΠΉΠ» class A { A(int _r = 1, int _m = 2); int r, m; }; // .cpp Ρ„Π°ΠΉΠ» A::A(int _r, int _m):r(_r),m(_m) // Π½ΡƒΠΆΠ½Π° Π»ΠΈ инициализация _r ΠΈ _m ? { } 

Or is it better to do the opposite: initialization in .cpp , but not in .h ?

    1 answer 1

    Arguments by default must be specified in the function prototype only. At the same time, if some parameter is omitted, all those to the right of it should also be omitted.

    • Those. in the .h file you need to write A(int = 1, int = 2); ? - btws
    • @btws yes. And it is true that the names in the announcement can also be omitted. - AivanF.