more operator overloading

Discussion in 'C++' started by BKurosawa, Jul 25, 2007.

  1. BKurosawa

    BKurosawa New Member

    Joined:
    Jul 24, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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];
    }
    
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,345
    Likes Received:
    382
    Trophy Points:
    83
    Can you share the function declaration and function definition of translateIndexToZeroBased
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice