Hi, it happen to me this thing: I create lightmap[4] element and dimensione map became 4; is I do lightmap[6] = Light(); then 6 element...why this?
Code:
map<int,Light> lightmap; lightmap[4] = Light();
Printable View
Hi, it happen to me this thing: I create lightmap[4] element and dimensione map became 4; is I do lightmap[6] = Light(); then 6 element...why this?
Code:
map<int,Light> lightmap; lightmap[4] = Light();
I don't understand what you are asking.Quote:
Originally Posted by mickey
I thought lightmap[4] = light(); create an element with index <int=4, > ...Code:
lightmap[4] = light(); int i = lightmap.size(); printf("ADDING LIGHT dimensione <map> %i\n" ,i); //this print 4...
I am still not completely understanding you. If you mean that it is creating them element lightmap[4] then yes it does do that. If you are mean that it should create elements lightmap[0] through lightmap[4] then no it does not do that.Quote:
Originally Posted by mickey
lightmap.size() only returns how many elements the map has, not the key of any one particular element. So, if you did the following:
The output would be 3.Code:
map<int, Light> lightmap; lightmap[3] = light(); lightmap[4] = light(); lightmap[5] = light(); int i = lightmap.size(); printf("ADDING LIGHT dimensione <map> %i\n" ,i);
A map is declared as "map <key type, value type, ...>" where the key type is the type of key you will be using. You can then use the brackets [] to get or set the value at map element [key]. So when you call lightmap[4] you are NOT telling it to create lightmap[0] through lightmap[4], you are simply saying I am holding this value at element location named 4 in the map named lightmap. You could have declared your map as:
map<string, Light> lightmap;
And changed
lightmap[4] = light();
to
lightmap["Four"] = light();
Does this help?
The `i` should be 1, and I cann't reproduce your problem...Quote:
Originally Posted by mickey
here's my code
Code:
class A { }; int main() { map<int,A> m; m[4]=A(); cout<<m.size(); return 0; }
and it prints `1`
my problem probabily was another:
now I need to to a thing (but I dont know how):Code:
map<int, Light> lightmap; lightmap[3] = light(); lightmap[4] = light();. lightmap[5] = light(); int i = lightmap.size(); printf("ADDING LIGHT dimensione <map> %i\n" ,i); "ADDING LIGHT dimensione <map> %i\n" ,i); //this should print 3
here above I need to put in a for a my Light class function; but the for is working on elements 0,1,2; I need to use map with KEY 3,4,5 (they're iserted before).Code:
int size = lightmap.size(); for (int i=0; i<size; i++) { lightmap[i].DOSomething(); }
Are u understand? thanks
Code:
for(QMap<int, Light>::iterator iter = lightmap.begin(); iter!=lightmap.end();++iter){ iter.data().doSomething(); }
The same goes with std::map, just the iterator may behave different (just look at its docs to see what member you need to access). It'll probably be "iter->doSomething()".
wysota's right, just use the`iterator`
And seems your English's poor:p
And it seems your English's poor. ;)Quote:
Originally Posted by bood
I thought it can be ignored in oral English...can't it?Quote:
Originally Posted by Michiel
Are we speaking?
Stop the flame, please.
Not if you prepend it with 'And'. Anyway, what relevance does it have? As long as it's not 1337-speak and we can understand each other...Quote:
Originally Posted by bood