Re[2]: Насколько оправданы жалобы компилятора на ambiguous conversion
От: Евгений Музыченко Франция https://software.muzychenko.net/ru
Дата: 10.10.17 10:48
Оценка:
Здравствуйте, uzhas, Вы писали:

U>вместо многобукв лучше бы выложил пример кода


  Код
class C64 {

  unsigned __int64 Value;

  public:

  C64 () : Value (0) { }

  operator unsigned __int64 () const { return Value; }
  operator __int64 () const { return Value; }
  void operator = (unsigned __int64 S) { Value = S; }
  void operator = (__int64 S) { Value = S; }

};

void f () {

  C64 c;

  int i = 0;
  unsigned int ui = 0;

  bool b = (c == 0);

  c = i;
  c = ui;

}

  Результат
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.207 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

convops.cpp
convops.cpp(23) : error C2593: 'operator ==' is ambiguous
could be 'built-in C++ operator==(unsigned __int64, int)'
or 'built-in C++ operator==(__int64, int)'
while trying to match the argument list '(C64, int)'
convops.cpp(25) : error C2593: 'operator =' is ambiguous
convops.cpp(12): could be 'void C64::operator =(__int64)'
convops.cpp(11): or 'void C64::operator =(unsigned __int64)'
while trying to match the argument list '(C64, int)'
convops.cpp(26) : error C2593: 'operator =' is ambiguous
convops.cpp(12): could be 'void C64::operator =(__int64)'
convops.cpp(11): or 'void C64::operator =(unsigned __int64)'
while trying to match the argument list '(C64, unsigned int)'
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.