Bug Vanquisher

6 March 2007

Some corrections

Filed under: Bugz, C++ — Tanveer Badar @ 3:46 PM

There was a compilation error in my iterator code which I just found.

Instead of writing this

friend random_access_iterator operator + ( diff offset , const random_access_iterator& other )
{

#ifdef _SECURE_STL
if( c != other.c )
throw invalid_argument( );

#endif
return random_access_iterator( other ) += offset;
}

It should be written like this

friend random_access_iterator operator + ( diff offset , const random_access_iterator& other )
{

#ifdef _SECURE_STL
if( !other.c )
throw invalid_argument( );

#endif
return random_access_iterator( other ) += offset;
}

because being a friend function it does not have access to member c.

Also, I changed the definition of c from const cont* to cont*, because of compilation error in operator * ( ) and operator -> ( ). This change requires a const_cast< cont* > in the constructors where c is initialized.

Please check this code with and without the preprocessor symbol defined. Some more errors may have been hidden which I didn’t find. Do inform me to correct the code if you happen to find one.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: