Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ correction

Name: Anonymous 2009-11-28 12:16

Hi /prog/

http://pastebin.com/meb2ac2d

Line 45, part of find_idea_id().

I want to give 'it' a default value, null pointer. It won't compile, can't understand how it should be typed differently.

Help me out :3

Name: HMA 2009-11-28 12:44

>>3
An iterator isn't an int nor a pointer, and there isn't any implicit conversion between these types. "Null pointer" isn't an iterator.

Try making it std::vector<Idea>::iterator find_idea_id(const unsigned long int& idea_id, std::vector<Idea>::iterator& it = std::vector<Idea>::iterator() ) const;. Not sure if that'll compile but it makes a bit more sense anyway.

In the worst case you could write two functions with a different signature instead:
std::vector<Idea>::iterator find_idea_id(const unsigned long int& idea_id ) const;
std::vector<Idea>::iterator find_idea_id(const unsigned long int& idea_id, std::vector<Idea>::iterator& it) const;

and implement the first one as
find_idea_id(const unsigned long int& idea_id) {
   return find_idea_id(idea_id, idea_registry_.begin() ); // or whatever
}


I don't really get what you want to do in the first place though. What's the point of the iterator argument? And stuff like unsigned long int& get_idea_id(); or const unsigned long int& is useless, it's a crappy int, just take it as a non-const non-reference argument like a man. Performance will be identical. I guarantee it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List