On Wednesday, October 09, 2013 16:13:48 Roman wrote: > > In fact, since the template could be in a library, and code > > could use that library well after the library has been > > written... > > As such, there is a fundamental conflict between how templates > > work and how virtual functions work. They just don't mix. > > Seems, the same problem doesn't allow auto attribute to virtual > functions, because technically ,I think, possible get type from > implemented functions, and if code trying to use return type not > appropriate manner then throw runtime exception.
auto works fine as long as the body is there, since all auto means is that the type is inferred when the function is compiled. However, anything that overrides that function must return either the same type or a covariant type. So, using auto with virtual functions will work if you're returning the right type, but it's probably better to just give the explicit type. - Jonathan M Davis