C++14 Question about auto

Looking over some of the new stuff in C++14 I notice you can use "auto" for the return type of a function. I've messed with it a bit but it just feels weird. Maybe it's because I'm not used to it or something but I would still rather write

 
  int getX(){ return x; }


instead of

 
  auto getX() { return x; }


So I guess I'm just curious. Are you guys using it? Does using auto over assigning the proper return type have any benefit?
Last edited on
I agree. I prefer writing the return type explicitly. It makes it much easier to see what the function returns, and if I happen to make a mistake while implementing the function the compiler will let me know right away if the types don't match.

Using auto return type does not work if you separate code into header and source files. It's mainly useful when working with templates in situations where the return type depends on other types.
Last edited on
Topic archived. No new replies allowed.