What's the difference between type and name in C++?

前端 未结 3 1737
予麋鹿
予麋鹿 2021-01-01 12:28

I am reading this Stack Overflow question, and I added a constructor to the code from that question as the follwing,

class Foo {
    struct Bar { 
              


        
3条回答
  •  梦毁少年i
    2021-01-01 13:16

    The question you link explains a lot but as a supplement to what is being written there...

    1. The main difference is that in the second line auto b=... you let the compiler deduce the type of the expression. You can't specify the type, as the name of the type is hidden. The type though is usable (at least from the compiler)

    2. You expose the name of the type publicly so it can be used.

    This is a very nice answer https://stackoverflow.com/a/13532882/3037915

    To try to answer the question in the header, you may consider type as a shape and the name of the type as the name you use to refer to a particular shape. Even if the name of the "shape" is hidden, the shape still exists and can be used.

提交回复
热议问题