What is the point of the 'auto' keyword?

后端 未结 8 913
暗喜
暗喜 2020-12-16 03:30

So I understand using var in C# makes sense because you have anonymous types that are compiler derived. C++ doesn\'t seem to have this feature (unless I\'m wron

8条回答
  •  星月不相逢
    2020-12-16 04:04

    so, let's learn type inference first which is basically refers to automatic deduction of the data type of an expression in a programming language.

    before C++ 11 all the variables in c++ have to explicitly declare but after the release of c++ 11, the compiler itself deduces the type of the variable at runtime.

    we can use it for variables and even in the case of function return types. but, it's suggested to avoid using auto in function return type.

提交回复
热议问题