What does the name after the closing class bracket means?

后端 未结 4 1657
庸人自扰
庸人自扰 2021-02-08 14:45

I\'ve encountered this code example and I remembered I\'ve seen it before and I didn\'t know what it is for and what it does? I\'ve searched on the internet but without luck.

4条回答
  •  天涯浪人
    2021-02-08 15:39

    You declare variables using the format type variable_name;. For example:

    A x;
    

    Where A may be the name of a class.

    But instead of using a pre-existing class type, you can also define the class at the same time as you declare a variable of the new class's type:

    class { ... } x;
    

    or define the class and give it a name:

    class A { ... } x;
    

    In C++ it is common to just define the class and give it a name, but leave off the variable:

    class A { ... };
    

    but you don't have to leave off the variable.

提交回复
热议问题