What is a Class and Object in C++?

前端 未结 20 1018
走了就别回头了
走了就别回头了 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: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.

提交回复
热议问题