(C++) operator[] überladung
-
ich habe den operator[] für eine klasse überladen. nun kommt folgender fehler, den ich nicht versteht.
hat jemand eine erklärung? bitte, es wäre dringend.start.cpp: In function
void start()': start.cpp:26: choosing
type& array<type>::operator[](long unsigned int) [with
type = long unsigned int]' overoperator[]' start.cpp:26: because worst conversion for the former is better than worst conversion for the latter start.cpp:26: choosing
type& array<type>::operator[](long unsigned int) [with
type = long unsigned int]' over `operator[]'
start.cpp:26: because worst conversion for the former is better than worst
conversion for the latterbjörn
-
diese schei* smilies. braucht man so was wirklich?
tart.cpp: In function
void start()': start.cpp:26: choosing
type& array<type>::operator[](long unsigned int) [with
type = long unsigned int]' overoperator[]' start.cpp:26: because worst conversion for the former is better than worst conversion for the latter start.cpp:26: choosing
type& array<type>::operator[](long unsigned int) [with
type = long unsigned int]' over `operator[]'
start.cpp:26: because worst conversion for the former is better than worst
conversion for the lattercompiler ist g++
-
zeig uns mal die signatur des operator[] und wie du ih aufrufst (+ deklaration der variablen)
-
template<class type> class array /* : public interface::array */ { protected: type* _pointer; unsigned long _size; public: inline array(void) { _pointer = (type*)0; _size = 0; } inline array(register type* pointer, register const unsigned long size) { _pointer = pointer; _size = size; } inline virtual void init(register type* pointer, register const unsigned long size) { _pointer = pointer; _size = size; } inline virtual const type& operator[](register const unsigned long index) const { return _pointer[index]; } inline virtual type& operator[](register const unsigned long index) { return _pointer[index]; } inline virtual const type* address(void) const { return _pointer; } inline virtual type* address(void) { return _pointer; } inline virtual const unsigned long size(void) const { return _size; } inline virtual array& operator=(register const array<type>& a) { if(_size < a._size) { return *this; } for(unsigned long i = 0; i < _size; i++) { _pointer[i] = a._pointer[i]; } return *this; } inline virtual operator type*(void) { return _pointer; } inline virtual operator const type*(void) const { return _pointer; } };
aufruf und deklaration:
array<unsigned long> blabla; blabla[0] = 100;
-
Hi,
die Frage scheint wenig mit dem Compiler selbst zu tun zu haben -> verschoben nach "C++".