Seite 1 von 1

[gelöst] Operant mehrdeutig unter Windows

Verfasst: 20. Dezember 2010 17:19
von BartSimpson
Hallo Leute,
ich folgendes Problem: Unter Linux läßt sich der Code übersetzen.
Unter Windows bekomme ich die Fehlermeldung, das der Operator mehrdeutig ist. Nur fällt mir dafür keine Lösung ein. Könnte mir jemand von euch helfen? Schon mal vielen Dank im Vorraus.
Ich habe die beiden Dateien mal angehangen.
Fehlermeldung:
ParametersRecord.cpp
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(44) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, quint16)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(48) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, quint16)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(49) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, int)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(50) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, int)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(51) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, int)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(58) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, quint16)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(62) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, quint16)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(66) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, quint16)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(67) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, int)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(68) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, int)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(69) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, int)'
C:\c++\fastcgi\lib\plugins\FastCgiInterface\ParametersRecord.cpp(76) : error C25
93: 'operator [' is ambiguous
c:\c++\qt\4.7.0\include\qtcore\../../src/corelib/tools/qbytearray.h(172)
: could be 'const char QByteArray::operator [](int) const'
c:\c++\fastcgi\lib\plugins\fastcgiinterface\UnsignedByteArray.h(29): or
'quint8 FastCgiQt::UnsignedByteArray::operator [](int) const'
while trying to match the argument list '(const FastCgiQt::UnsignedByteA
rray, quint16)'
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\amd64\cl.exe' : return
code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\Bin\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\Bin\amd64\nmake.exe"' : return code '0x2'
Stop.

Verfasst: 21. Dezember 2010 08:34
von franzf
Spar dir das "using ..." in UnsignedByteArray - ist unnötig. operator[] in einer abgeleiteten Klasse anbieten überdeckt ALLE Member mit gleichem Namen (unbeachtet der Signatur!) der Baseklasse.
Versuch das mal:

Code: Alles auswählen

#include <iostream>
using namespace std;

struct Base {
  int array[100];
  int operator[](int i) const {
    cout << "Base::op[] const\n";
    return array[i];
  }
  int& operator[](int i) {
    cout << "Base::op[]\n";
    return array[i];
  }
};

struct Derived : Base {
  unsigned int operator[](int i) const {
    cout << "Derived::op[]\n";
    return static_cast<unsigned int>(Base::operator[](i));
  }
};

int main() {
  Derived d;
  int x = d[20];
  cout << x << endl;
  d[21] = 100; // Fehler: Als linker Operand einer Zuweisung wird L-Wert erfordert
  cout << d[21] << endl;
}
Die non-const-Variante ist in Derived nicht mehr verfügbar, deshalb der Fehler.

Das mit dem überdecken gilt natürlich nicht nur für operator[], sondern für alle Methoden.

Grüße
Franz

Verfasst: 21. Dezember 2010 13:21
von BartSimpson
Viele Dank, für den Tipp.
Jetzt läßt sich das ganze übersetzten.
zwar meckert, der Linker jetzt noch rum, aber aber erst mal selber versuchen das zu beheben.:)