:10:27: error: prototype for 'decltype (MyClass<T>::_id) MyClass<T>::getId()' does not match any in classgetId() -> decltype(_id);auto MyClass<T>::getId() -> decltype(MyClass<T>::_id)
{
因为auto和decltype都用于推断类型。我以为它们是一样的。不过,我认为它们不可能完全不同。我可以想出一个简单的例子,其中i的类型在以下两种情况下都是相同的。auto i = 10; and decltype(10) i = 10;
那么,在哪些可能的情况下,auto和decltype的行为是相同的呢?
add(auto a, auto b); // the decltype(a) is needed to make clang happy// see: https://stackoverflow.com/questions/62779242
return number<decltype(a)>{a}.