Почему конструкция with = vs. () имеет различия?C++

Программы на C++. Форум разработчиков
Anonymous
 Почему конструкция with = vs. () имеет различия?

Сообщение Anonymous »

Смотрю на это:

Код: Выделить всё

#include 

template  class Any {
T value_;

public:
explicit Any(T value) : value_(value) {}
};

int main() { Any a = 1; }
Мы уступаем:

Код: Выделить всё

other.cpp:10:18: error: no viable constructor or deduction guide for deduction of template arguments of 'Any'
int main() { Any a = 1; }
^
other.cpp:3:29: note: candidate template ignored: could not match 'Any' against 'int'
template  class Any {
^
other.cpp:7:12: note: explicit constructor is not a candidate
explicit Any(T value) : value_(value) {}
^
1 error generated.
но если мы изменим основную функцию следующим образом:

Код: Выделить всё

int main() { Any a(1); }
Тогда предупреждения компилятора исчезнут. Каково логическое обоснование этого решения в рамках стандарта? Оба вызывают один и тот же конструктор.

Подробнее здесь: https://stackoverflow.com/questions/790 ... ifferences

Вернуться в «C++»