Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Why not declare a class or enumerated value in a statement in C++ and define a variable of that type at the same time

Shulou Source: shulou.com Published: 2022-06-01 19:11:51 09月30日 Update

This article mainly explains why C++ should not declare a class or enumerated value in a sentence and define the type of variable at the same time. The content in the article is simple and clear, and it is easy to learn and understand. Next, please follow the editor's train of thought slowly and deeply, together to study and learn why C++ should not declare a class or enumerated value in a sentence and define the type of variable at the same time.

Do not declare a class or enumerated type in a statement and define variables of that type at the same time

Reason (reason)

Mixing the definitions of types and entities is difficult and unnecessary.

Translator's note: programming is not a flashy skill, and there is no need to change the code structure in order to reduce the number of lines.

Example, bad (negative example) struct Data {/ *... * /} data {/ * * /}; Example, good (good example) struct Data {/ *... * /}; Data data {/ *... * /}; Enforcement (implementation recommendation)

If the last} of the class or enumerated type definition is not immediately followed by;, or prompt when; is missing.

Thank you for your reading, the above is the content of "Why C++ should not declare a class or enumerated value in a sentence while defining this type of variable". After the study of this article, I believe you have a deeper understanding of why C++ should not declare a class or enumerated value in a sentence and define this type of variable at the same time, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Types variables at the same time statements statements learning necessity content examples code reasons tails entities that is suggestions ideas situations articles more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi Shulou Technology Linux Docker