Semicolons in a class definition

后端 未结 2 1057
失恋的感觉
失恋的感觉 2020-12-10 15:21

I was reading this gotw and here\'s a code sample from there:

struct X {
  static bool f( int* p )
  {
    return p && 0[p] and not p[1:>>p[2];         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 16:20

    ; is an empty statement. You can have as many empty statements as you want. It is absolutely correct.

    int foobar(int arg)
    {
        return 0;
    };
    

    is the same as

    int foobar(int arg)
    {
        return 0;
    }
    /*DO NOTHING*/;
    

    Similar question: Why are empty expressions legal in C/C++?

    Edit:

    A declaration of a member is also a statement. So empty statement inside class is something like an << empty >> declaration statement inside class :)

提交回复
热议问题