errors with assert()

We are writing our own string class(mystring), and I am having a problem with my operator[] overload. The function works fine, but we are supposed to use an assert to insure that the position passed to the function is less than the length of the array.

1
2
3
4
5
6
7
8
char mystring::operator [ ](size_t position) const
	//Precondition: position < length()
	assert(position < length);
	{
		char result;
		result = *(sequence+position);
		return result;
	}

length is a private member variable, position gets passed to the function, and both are of type size_t. They should both be in scope. The errors I get are:

all errors are on the line assert(position<length):

error C2091: function returns function
error C2065: 'position' : undeclared identifier
error C2597: illegal reference to non-static member 'mystring::length'
error C3867: 'mystring::length': function call missing argument list; use '&mystring::length' to create a pointer to member
error C2568: '<' : unable to resolve function overload
Shouldn't the assert be placed inside the {} ?

1
2
3
4
5
6
7
8
char mystring::operator [ ](size_t position) const
	//Precondition: position < length()
{
  assert(position < length);
  char result;
  result = *(sequence+position);
  return result;
}
duh! That's why I love this site. I had looked at it for too long without seeing the obvious. Thanks
Topic archived. No new replies allowed.