Я знаю о явных преобразованиях, но их можно использовать только с векторами и функциями преобразования.Позвольте мне показать код, иллюстрирующий проблему:
Код: Выделить всё
#include
#include
// =============================
// Define the interface
template
concept ImplementsInterface = requires(T obj, int x)
{
{ obj.func(x) } -> std::same_as;
};
// =============================
// Here is one implementation of the interface
struct B
{
double func(int x) // Note the INCORRECT 'double' return type
{
return x + 5;
}
};
// This DOES produce a compiler error (yay!)
static_assert(ImplementsInterface);
// =============================
// Here is another implementation of the interface
struct C
{
int func(char x) // Note the INCORRECT 'char' argument
{
return x + 6;
}
};
// This DOES NOT produce a compiler error (and I want it to!)
static_assert(ImplementsInterface);
Я думаю, C::func(char) использует неявное преобразование из char->
Код: Выделить всё
int
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/784 ... -using-con