Created
April 2, 2014 11:59
-
-
Save jirihnidek/9932711 to your computer and use it in GitHub Desktop.
Pointer as key for C++ map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <map> | |
// Compile: g++ map_example.cc | |
// Run: ./a.out | |
int main(void) | |
{ | |
std::map<unsigned char*, int> paleta; | |
unsigned char rgb1[3], rgb2[3]; | |
rgb1[0] = 100; | |
rgb1[1] = 200; | |
rgb1[2] = 0; | |
rgb2[0] = 0; | |
rgb2[1] = 0; | |
rgb2[2] = 255; | |
paleta[rgb1] = 100; | |
paleta[rgb2] = 55; | |
std::cout << paleta[rgb1] << ", " << paleta[rgb2] << std::endl; | |
for( std::map<unsigned char*, int>::iterator ii=paleta.begin(); ii!=paleta.end(); ++ii) | |
{ | |
std::cout << "(" << (int)(*ii).first[0] << ", " | |
<< (int)(*ii).first[1] << ", " | |
<< (int)(*ii).first[2] << "): " << (*ii).second << std::endl; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment