|
-
May 29th, 2009, 02:17 PM
#13
Re: how to implement c++ table lookup?
 Originally Posted by Lindley
[][] should word automatically with a map< int, map<int,int> >.....
Although, there is one thing to be careful of. Using [] on a map *will* add that key to the map if it isn't there already (with a default-constructed value, in this case 0).
If you want to be able to test whether or not a pair is in the map yet, you'll have to use find() instead.
thanks for the warning.
my code looks like this:
Code:
int GetValueAt(int x,int y)
{
return table[x][y];
}
If I try some random x and y where table[x][y] doesn't exist, it will make one? And then return 0 ?
Last edited by sdcode; May 29th, 2009 at 02:19 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|