Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   more operator overloading (http://www.go4expert.com/forums/more-operator-overloading-t5450/)

BKurosawa 25Jul2007 06:38

more operator overloading
 
I get this error with this code:

error C2662: 'IntArray::translateIndexToZeroBased' : cannot convert 'this' pointer from 'const IntArray' to 'IntArray &'

Code:


int& IntArray::operator [](int index)
{
        static int sink;
        int zerobasedindex = translateIndexToZeroBased(index);
        if(zerobasedindex < 0 || zerobasedindex >= theSize)
        {
                cout<< "Problem with index (less than 0)" << endl;
                return sink;
        }

        return parray[zerobasedindex];
}

const int& IntArray::operator [](int index) const
{
        static int sink;
        int zerobasedindex = translateIndexToZeroBased(index);
        if(zerobasedindex < 0 || zerobasedindex >= theSize)
        {
                cout<< "Problem with index (l)" << endl;
                return sink;
        }
        return parray[zerobasedindex];
}


shabbir 25Jul2007 09:06

Re: more operator overloading
 
Can you share the function declaration and function definition of translateIndexToZeroBased


All times are GMT +5.5. The time now is 21:44.