C++ Is it correct to call class member variables “attributes”?

孤街浪徒 提交于 2019-12-05 07:12:53

Define "correct".

Referring to data members and member functions as "attributes/properties" and "methods", respectively, is common practice - it's the general OO wording. ("attributes" are used in C++ for something else, though, so this may very well be a source of confusion.)

The C++ standard, however, does not use these terms (apart from attributes of course, as explained above). If you don't want to risk anything and always be correct, use "data members" and "member functions".

But if you only want to explain C++ to a Java programmer, you may get away with "property" and "method" in the beginning.

I would not do that. While it can be understood in the general context of OO, it will be confusing in C++ as attribute has a precise definition in the standard, that is not that of data member.

A class' attributes would translate to its members. A method is not the same as a member function in general. But "In object-oriented programming, a method is a subroutine (or procedure) associated with a class." - Wikipedia.

In common words, an attribute describes something, "One of the attributes of this car is that it's quite long", or "one of the attributes of the giant panda is it's striking black and white colours".

I XML, attributes are used to add extra information in a tag, e.g <species id=3212>Ailuropoda melanoleuca<common_name>Giant Panda</common_name></species> - id is an attribute, Ailuropoda melanoleuca is a value, common_name a tag within species.

But I call the variables in a class "member variables", and functions in a class "member function" or "method".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!