Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    61
  • comments
    131
  • views
    32166

Find your pillow, boring entry inbound...

Sign in to follow this  

278 views

Recently I've been working on random stuff, mostly non-graphical, like scripting and now also a difference engine.
However when reading on STL iterators, I found a "bug" in Cprogramming.com s tutorial, as you can see an excerpt from here:

The old approach (avoid)
using namespace std;

vector<int> myIntVector;
// Add some elements to myIntVector
myIntVector.push_back(1);
myIntVector.push_back(4);
myIntVector.push_back(8);

for(int y=0; y{
cout<" ";
//Should output 1 4 8
}
--------------------------
The STL approach (use this)
using namespace std;

vector<int> myIntVector;
vector<int>::iterator myIntVectorIterator;

// Add some elements to myIntVector
myIntVector.push_back(1);
myIntVector.push_back(4);
myIntVector.push_back(8);

for(myIntVectorIterator = myIntVector.begin();
myIntVectorIterator != myIntVector.end();
myIntVectorIterator++)
{
cout<<*myIntVectorIterator<<" ";
//Should output 1 4 8
}




I looked at this and realised that the first example wont even compile, at least not on my compiler(DevC++), this is because the vectors can only be indexed(or whatever) by an unsigned integer or STL iterator and not by a regular integer. So yeah! They have a bug in their tutorial.

Oh and the difference engine is going good. I'm gonna try and port it to PHP since thats where it's gonna be used: at my friend's site.

I'm gonna install a new network card, I'll see you on the other side [smile].
Sign in to follow this  


2 Comments


Recommended Comments

I can index STL vectors just fine with a signed integer here, even with -Wall. I'm pretty sure the standard says you can, too.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!