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

Pages: 1-

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: Anonymous 2009-11-28 12:22

references can't be null

Name: Anonymous 2009-11-28 12:30

>>2
removing the '&' doesn't help, still the same error message. Hm, I'll post it, might be useful

./Idea Registry/idea_registry.h:45: error: default argument for parameter of type ‘__gnu_cxx::__normal_iterator<Idea_Registry::Idea*, std::vector<Idea_Registry::Idea, std::allocator<Idea_Registry::Idea> > >&’ has type ‘int’

flags: -std=c++98 -pedantic -Wall -Wextra

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.

Name: Anonymous 2009-11-28 12:47

>>4
thanks

Name: Anonymous 2009-11-28 13:09

OP here again, another problem. I can't find any cause of error.

./Idea Registry/idea_registry.cc:87: error: default argument given for parameter 2 of ‘std::ostream& Idea_Registry::print_idea(const long unsigned int&, std::ostream&) const’
./Idea Registry/idea_registry.h:28: error: after previous specification in ‘std::ostream& Idea_Registry::print_idea(const long unsigned int&, std::ostream&) const’

Name: Anonymous 2009-11-28 13:24

>>6
this problem seems quite fucktarded, ostream and iostream included, .h and .cc is identical.

it's simply std::ostream& os = std::cout -> wrong

Name: Anonymous 2009-11-28 13:31

>>7
nevermind, fix'd

Name: Anonymous 2009-11-28 14:02

Alright, another question:

A functions returns unsigned long int&

unsigned long int& function()
{
...

return 0;
}

result: error: invalid initialization of non-const reference of type ‘long unsigned int&’ from a temporary of type ‘int’

lol, help plz.

Name: Anonymous 2009-11-28 15:34

>>9
Why don't you use a sane programming language?

Name: Anonymous 2009-11-28 15:51

>>10
I just see it as a challenge.

Name: Anonymous 2009-11-28 16:26

>>9
You can't return a reference to a temporary. References must refer to l-values.

Name: Anonymous 2009-11-29 9:49

>>9
It's a fucking int. I told you, it doesn't matter, return it by value. The compiler will optimize it anyway.

Name: Anonymous 2009-11-29 11:27

>>12
oooh yes you can. have fun using it though

Name: Anonymous 2009-11-29 12:15

Use C++, get a STD.

Name: Anonymous 2009-11-29 12:22

>>15
Push C++, receive STD

Name: Anonymous 2009-11-29 14:52

This is fucking disgusting.

Name: Anonymous 2010-12-17 1:28

Xarn is a bad boyfriend

Name: Anonymous 2010-12-17 1:30

Xarn is a bad boyfriend

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