1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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,283
    Likes Received:
    364
    Trophy Points:
    83
    Can you share the function declaration and function definition of translateIndexToZeroBased
     

Share This Page