What is a Class and Object in C++?
Can we say that a Class is an Object?
An object is some data, which has an address in run-time memory.
There are different types of object (e.g. int, float, etc.). You can create user-defined types, called 'classes'.
For example, I can define Dog as a class ...
class Dog {};
... and then create several objects, each of which is one instance of that class ...
Dog fido;
Dog spot;
A class is not an object.
In simpler C language, a class is like a struct
type, but more complex.
Using a C struct
example as analogy:
struct class_ {
int attribute00;
float attribute02;
...
}
struct class_ object_ = {0, 0.0, ...};
struct class_
is act like a class
and object_
is act like an object
.
struct class_
has no physical storage in memory, object_
has physical storage in memory.
In human language, a word 'house' (as class
) can defined in dictionary as place to stay, with doors, with windows, and rooms that you can only speak with your mouth to tell other people what is a house. A physical house (as object
) is a solid build house on a land that you can move in and stay with your family.
A word 'house' take no physical occupation of land or space. A physical house occupy land and space.
An object is an instance of a class.
This is analogous to asking if a cat is a "My Kitten Mittens".
C++ supports many paradigms, but not the 'everything is an object' style of object-oriented programming. Classes exist in the source code, but do not exist at run time. Even runtime type information doesn't preserve Classes as object, but only provides a capability to get opaque ids which correspond to the type.
Class is collection of data and functions,its user defined data type.Class is specification for object.So you can say that object is variable for class or object is instance of class.