Код: Выделить всё
#include
// Forward declaration of construct, using return type deduction
template
auto construct(Args... args);
// Specialization for Version 1 – takes const reference
template
auto construct(const std::optional& o) {
return 0;
}
// Specialization for Version 2 – takes by value
template
auto construct(std::optional o) {
return 0;
}
int main() {
std::optional o;
construct(o); // fails
construct(o); // works
return 0;
}
Код: Выделить всё
error: function 'construct' with deduced return type cannot be used before it is defined
Мои вопросы:
- Почему конструкция не работает, но Конструкция работает?
- Как правильно объявить или структурировать это, чтобы можно было безопасно использовать выведенные специализации возвращаемого типа?
Подробнее здесь: https://stackoverflow.com/questions/797 ... d-when-usi
Мобильная версия