简体   繁体   中英

Difference between type and class in c++?

I notice that our home doesn't have this easy question, so I'll post it.

One says type is built-in type, such as int, long, char, etc, while class is a user-defined class.
Is it right?

Is it right?

No. From the C++ standard's working draft, we know that (emphasis mine):

A class is a type.

In particular, it is a compound type .
On the other side, char , int and so on are considered fundamental types .

See here for further details about types.

Type is something which defines the memory footprint of variable. For eg :- when I declare a variable as int , compiler allocates fixed amount of memory which may OR may not be different from other types float , double etc.

Similarly, a class is blue print of objects. It defines the layout of the object in memory. And hence class is also a type.

Type is more like name of your caste, For example: The object is of type int or employee(where employee is a class)

Class is telling you the structure of user defined type. call it blue print and what ever is convenient to you.

You can also say the class name is type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM