What is a Class and Object in C++?

前端 未结 20 947
走了就别回头了
走了就别回头了 2020-12-09 10:33

What is a Class and Object in C++?

Can we say that a Class is an Object?

相关标签:
20条回答
  • 2020-12-09 10:49

    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;
    
    0 讨论(0)
  • 2020-12-09 10:50

    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.

    0 讨论(0)
  • 2020-12-09 10:51

    An object is an instance of a class.

    0 讨论(0)
  • 2020-12-09 10:51

    This is analogous to asking if a cat is a "My Kitten Mittens".

    0 讨论(0)
  • 2020-12-09 10:54

    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.

    0 讨论(0)
  • 2020-12-09 10:54

    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.

    0 讨论(0)
提交回复
热议问题