"Michael" <mi*******@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
Victor Bazarov wrote:
>Michael wrote:
I could understand the difference between class and object. However, I
could find out a good definiton of type. how to understand the
relaitonship between type, class, and object? Thanks!
'class' is a user-defined type (UDT, a very common TLA in OOP). A type
is a "kind" of objects, definiting common traits of all *instances* of
that type ("objects"). Types in C++ are characterized by the name and
the *definition*. Types in C++ consist of built-in and user-defined.
The definition of a UDT contains *declarations*, which describe the
representation and the behaviour of the instances of the UDT. The
representation and the behaviour of built-in types is defined in the
Standard.
I would think of type as "Class". Is thar right? There is no difference
to call "Class" or "Type".
Where do you get the word "Class" from? Are you referring to the keyword
"class", which denotes one kind of user-defined-type? (The other being the
keyword "struct".)
The concept of "type" in C++ means, basically, "what kind of thing is
this?". So, some examples of types are: int, char, and unsigned long.
These are built-in types, already defined in the language for you.
If you have a class definition like this:
class MyClass { /* member stuff here */ };
....then you have a user-defined type (or UDT), whose type is MyClass.
Likewise, the definition
struct MyStruct { /* member stuff here */ };
....defines a UDT, whose type is MyStruct.
(Sometimes in OOP, the terms "UDT" and "class" are used interchangeably, but
to me that can be confusing, since in C++ we also have UDTs which are
struct's, as I've shown.)
Given the above definitions,
MyClass aMyClassInstance;
....declares a variable called aMyClassInstance, whose type is MyClass, and
MyStruct aMyStructInstance;
....declares a variable called aMyStructInstance, whose type is MyStruct, and
-Howard