C++ Constructor initialization list strangeness

前端 未结 5 1488
离开以前
离开以前 2021-02-20 05:58

I have always been a good boy when writing my classes, prefixing all member variables with m_:

class Test {
    int m_int1;
    int m_int2;
public:
    Test(int          


        
5条回答
  •  暖寄归人
    2021-02-20 06:28

    I imagine this works because you were using int1 in the initialiser list, and the only things you can initialise are member variables => it was in fact unambiguous which variable was being initialised.

    Whether all C++ compilers would be this forgiving is another matter!

提交回复
热议问题