I don't understand what you are asking.Originally Posted by mickey
I don't understand what you are asking.Originally Posted by mickey
I thought lightmap[4] = light(); create an element with index <int=4, > ...Qt Code:
lightmap[4] = light(); int i = lightmap.size(); printf("ADDING LIGHT dimensione <map> %i\n" ,i); //this print 4...To copy to clipboard, switch view to plain text mode
Regards
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.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.Qt 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);To copy to clipboard, switch view to plain text mode
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...Originally Posted by mickey
here's my code
Qt Code:
class A { }; int main() { map<int,A> m; m[4]=A(); cout<<m.size(); return 0; }To copy to clipboard, switch view to plain text mode
and it prints `1`
1. Users don't have the manual, and if they did, they wouldn't read it.
2. In fact, users can't read anything, and if they could, they wouldn't want to.
my problem probabily was another:
now I need to to a thing (but I dont know how):Qt 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 3To copy to clipboard, switch view to plain text mode
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).Qt Code:
int size = lightmap.size(); for (int i=0; i<size; i++) { lightmap[i].DOSomething(); }To copy to clipboard, switch view to plain text mode
Are u understand? thanks
Regards
Qt Code:
for(QMap<int, Light>::iterator iter = lightmap.begin(); iter!=lightmap.end();++iter){ iter.data().doSomething(); }To copy to clipboard, switch view to plain text mode
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()".
Last edited by wysota; 7th June 2006 at 08:30.
mickey (10th June 2006)
wysota's right, just use the`iterator`
And seems your English's poor![]()
Last edited by bood; 8th June 2006 at 05:14.
1. Users don't have the manual, and if they did, they wouldn't read it.
2. In fact, users can't read anything, and if they could, they wouldn't want to.
And it seems your English's poor.Originally Posted by bood
![]()
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
mickey (10th June 2006)
I thought it can be ignored in oral English...can't it?Originally Posted by Michiel
1. Users don't have the manual, and if they did, they wouldn't read it.
2. In fact, users can't read anything, and if they could, they wouldn't want to.
Are we speaking?
Regards
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...Originally Posted by bood
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Bookmarks