What exactly are C++ definitions, declarations and assignments?

前端 未结 8 1272
长情又很酷
长情又很酷 2020-11-30 08:52

I tend to use the words define, declare and assign interchangeably but this seems to cause offense to some people. Is this justified? Should I only use the word declare for

8条回答
  •  广开言路
    2020-11-30 09:30

    It might depend on the language, as has been said. I think it really depends on whether the words are used for things like classes. For most of the data types discussed here, the question might not have much relevance. In C++ (see c++ - What is the difference between a definition and a declaration?), a class or struct always has precisely one definition but can be declared zero or more times. A class cannot be declared without a definition. So "declared" might be synonymous with "used".

    In most languages, simple types such as integers do not need definitions in the manner that classes do.

提交回复
热议问题