Reputation: 43
I took a quiz in my advanced C++ course and was surprised when I got points taken off from the following question:
Specify four attributes of a variable in C++.
My answer: size, type, class, public
Size and type were accepted but class and public weren't. My understanding is that an instance of a class is an attribute of the instantiated variable. And when defining a class, the member variables can be public or private attributes of the class.
I asked my TA and professor and they claim I am wrong because an instance variable is not the same as a data type variable like int, double, char, etc.
So my question boils down to: Do instances of a class act the same as primitive type variables? Why or why not?
Upvotes: 1
Views: 2818
Reputation: 11789
Your instructor was somewhat correct.
Your instructor was probably looking for:
There are also other properties, such as Address and Linkage, but it is unlikely your professor was referring to those.
My understanding is that an instance of a class is an attribute of the instantiated variable
No, it (the class) is the type of the variable (which is a property, as quoted above)
And when defining a class, the member variables can be public or private attributes of the class.
Visibility only applies to a small subset of variables, and in the case of member variables, they can be marked protected
in a class as well.
Do instances of a class act the same as primitive type variables? Why or why not?
I don't understand what you mean by "act". If you mean, can they be assigned to, can they be passed to functions, do they use similar syntax, then yes. If you are referring to operations, their members, their size, then no.
Upvotes: 1