QOTD
-
Ryan Johnston wrote: Are you serious? yes, 100%. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
:omg:
David Wulff http://www.davidwulff.co.uk
One 18yrs male, red and white, good condition; daily servicing required. £500 collect ono.
-
The answer is C) (*it) is the value, so &(*it) is the address of the value. Or did I miss something? I vote pro drink :beer:
-
there's probably some deep metaphysical reason why people want to use (*it). instead of it-> . i just do it because that's how i learned it. Ryan Johnston wrote: What kind of programming do you do? a little of everything, but mostly 2d graphics. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
Looking into the MSDN can open eyes! iterator overloads operator*. plain and simple. Somehow the STL trys to use references wherever possible.
-
:omg:
David Wulff http://www.davidwulff.co.uk
One 18yrs male, red and white, good condition; daily servicing required. £500 collect ono.
sadly, that used up the last of my "serious" for today. time for beer. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
-
sadly, that used up the last of my "serious" for today. time for beer. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
lol. :)
David Wulff http://www.davidwulff.co.uk
One 18yrs male, red and white, good condition; daily servicing required. £500 collect ono.
-
The answer is C) (*it) is the value, so &(*it) is the address of the value. Or did I miss something? I vote pro drink :beer:
Correct :D! Altough I believe the questioner ment D).
-
Looking into the MSDN can open eyes! iterator overloads operator*. plain and simple. Somehow the STL trys to use references wherever possible.
Colin Leitner wrote: plain and simple what's plain and simple? *it.menuItem // does not compile (*it).menuItem // compiles nicely -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
-
Colin Leitner wrote: plain and simple what's plain and simple? *it.menuItem // does not compile (*it).menuItem // compiles nicely -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
iterator is a struct. now operator* returns the value (if I understood that right). so you need it.operator*().menuItem or (*it).menuItem. This has nothing to do with any pointer syntax.
-
iterator is a struct. now operator* returns the value (if I understood that right). so you need it.operator*().menuItem or (*it).menuItem. This has nothing to do with any pointer syntax.
but it has a lot to do with precedence. overloading an operator, such as "*" doesn't change its precedence. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
-
but it has a lot to do with precedence. overloading an operator, such as "*" doesn't change its precedence. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
Yes but '->' won't work at all! You cannot change operator precedence at all, that's correct. a+++++b ;)
-
The answer is C) (*it) is the value, so &(*it) is the address of the value. Or did I miss something? I vote pro drink :beer:
-
Yes but '->' won't work at all! You cannot change operator precedence at all, that's correct. a+++++b ;)
are you 100% sure of that?
#include <vector>
struct sc
{
sc(int i) {v=i;}
sc() {v=0;}int v;
};
int main(int argc, char* argv[])
{std::vector <sc> myvec;
myvec.push_back(sc(10));
myvec.push_back(sc(40));
myvec.push_back(sc(60));
myvec.push_back(sc(15));
myvec.push_back(sc(13));
myvec.push_back(sc(11));for (std::vector<sc>::iterator it = myvec.begin(); it!=myvec.end(); it++)
{
if ((*it).v != it->v)
{
printf("%d != %d\n", (*it).v, it->v);
}
}
return 0;
}cause this works fine. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
-
What's wrong with 'it' alone - (as long as the context indicates a valuetype * is expected)
You don't need to sleep to see a nightmare Anne Clark [sighist]
peterchen wrote: What's wrong with 'it' a You mean, aside from being incorrect code? ;) An iterator is an opaque data type, like say POSITION in MFC. You can't make any assumptions about it actually being a pointer to the underlying data, because iterator is not documented as such. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
I don't know anything about STL, what is an STL iterator? Having said that the only option that look reasonable is D (although other options are possible if iterators have overloaded operators). Ryan Johnston
It's a type used to iterate (!) through the elements in an STL collection (vector, list, etc.) --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
are you 100% sure of that?
#include <vector>
struct sc
{
sc(int i) {v=i;}
sc() {v=0;}int v;
};
int main(int argc, char* argv[])
{std::vector <sc> myvec;
myvec.push_back(sc(10));
myvec.push_back(sc(40));
myvec.push_back(sc(60));
myvec.push_back(sc(15));
myvec.push_back(sc(13));
myvec.push_back(sc(11));for (std::vector<sc>::iterator it = myvec.begin(); it!=myvec.end(); it++)
{
if ((*it).v != it->v)
{
printf("%d != %d\n", (*it).v, it->v);
}
}
return 0;
}cause this works fine. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
I'm sorry, I forgot they implemented the operator-> too (argh! operator overloading begins to suck ;)
-
I'm sorry, I forgot they implemented the operator-> too (argh! operator overloading begins to suck ;)
Clickety.I choose a random iterator type, but they all behave the same.
-
Congrats to Christian Graus for thinking up the QOTD. I believe this is the first one I've seen from a CPian. Of course, I can't answer because I haven't a clue when it comes to STL. So I'll just leave the answering of it to the rest of you. :) David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig
Ahh, my brain is switched off. For that past few days I've been going though interfaces/abstract classes and coding COM objects in pure C++, to gain a better understanding. Now I think I know this one, as I use them quite a bit, but I've not got the energy to make sure. brain is mush, and I've just finished watching Lord 'o' the Rings. I'm battered, and I think I'm going to have another glass of wine...... :-D(stupid grin)
-
Congrats to Christian Graus for thinking up the QOTD. I believe this is the first one I've seen from a CPian. Of course, I can't answer because I haven't a clue when it comes to STL. So I'll just leave the answering of it to the rest of you. :) David Stone It seemed similar to someone saying, "Would you like to meet my knife collection?" Ryan Johnston on Elaine's sig
What about option E) const_cast<Type&>(*it).Foo() ? Otherwise you're editing a copy of the object. Todd Smith
-
there's probably some deep metaphysical reason why people want to use (*it). instead of it-> . i just do it because that's how i learned it. Ryan Johnston wrote: What kind of programming do you do? a little of everything, but mostly 2d graphics. -c
Conservative: One who admires radicals centuries after they're dead. -- Leo C. Rosten
Chris Losinger wrote: there's probably some deep metaphysical reason why people want to use (*it). instead of it-> . i just do it because that's how i learned it AFAIR it is just because early versions of STL and/or the C++ compiler used those days didn't support the "intuitive" syntax. In our days using
it->Something
should work quite fine. -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D ) -
peterchen wrote: What's wrong with 'it' a You mean, aside from being incorrect code? ;) An iterator is an opaque data type, like say POSITION in MFC. You can't make any assumptions about it actually being a pointer to the underlying data, because iterator is not documented as such. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
Michael Dunn wrote: You can't make any assumptions about it actually being a pointer to the underlying data, because iterator is not documented as such. But you can expect it to support (part of) the syntactic interface of a pointer (operator *(), operator ->() and for some iterators also operator []()) Therefore if you use it in generic (templated) code you can expect it to work like a pointer. We have to be very careful with terms like "pointer", "data" and so on here. What exactly is meant by "pointer". A pointer in the C sense or a "thing" that supports the interface of a pointer and therfore acts like a pointer (which is exactly the idea of a generic iterator used in STL). I am still not sure about the intention of the original question: Given an STL iterator it, what is the correct way to access a pointer to the iterator's data? Does it mean:
- a C-style pointer to the data the iterator refers to? Then the correct answer is c), even if I am not sure it should be written as &(*it) instead of &*it .
- a "pointer interface" to the data the iterator refers to? Then the correct answer is a).
- a "pointer inteface" to the iterator itself? Then the correct answer is b).
- ...
-- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )