Semicolon after class declaration braces

前端 未结 7 831
忘了有多久
忘了有多久 2020-11-29 20:17

In C++ classes, why the semi-colon after the closing brace? I regularly forget it and get compiler errors, and hence lost time. Seems somewhat superfluous to me, which is un

相关标签:
7条回答
  • 2020-11-29 20:59

    I guess it's because classes are declarations, even when they need braces for grouping. And yes, there's the historical argument that since in C you could do

    struct
    {
      float x;
      float y;
    } point;
    

    you should in C++ be able to do a similar thing, it makes sense for the class declaration to behave in the same way.

    0 讨论(0)
提交回复
热议问题