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

Pages: 1-

what's wrong with this?

Name: Anonymous 2006-05-19 18:41

#include<iostream>

using namespace std;

struct db : public unary_function<int, int> {
  int operator()(const int& x) { return 2 * x; }
};

void f(int x, unary_function<int, int> t) {
  cout << t(x) << endl;
}

int main() {
  f(2, db());
  return 0;
}


Gives me a compile error:

test.cpp: In function ‘void f(int, std::unary_function<int, int>)’:
test.cpp:11: error: no match for call to ‘(std::unary_function<int, int>) (int&)’

Name: Anonymous 2006-05-19 19:07

template <typename T>
void f(int x, T t) {
  cout << t(x) << endl;
}

magick lol

Name: Anonymous 2006-05-19 19:15

>>1
you're using unary_function<int, int> as an argument for f, but passing db.  db has operator() defined, unary_function<> does not.  thus, t(x) fails.

Name: Anonymous 2006-05-19 19:24

Is there a way to do this without using templates? Why doesn't unary_function have any member functions?

Name: Anonymous 2006-05-19 19:42

>>4
all unary_function is is a base class which typedefs the argument and result types to argument_type and result_type.  these types are necessary for certain STL uses.

if you don't need these types defined, just overloading operator() in any normal class will suffice.

Name: Anonymous 2006-05-19 21:02

Since when can structs inherit and overload operators?

Name: Anonymous 2006-05-20 0:03

>>6
learn C++ please, structs are just classes with everything public by default.

Name: Anonymous 2006-05-20 9:15

>>6
Don't listen to >>7 you don't have to learn C++. Just smash your face against a wall and you'll achieve the same affect.

Name: Anonymous 2006-05-20 12:20 (sage)

>>8
Yeah, if this was java.

Name: Anonymous 2006-05-20 14:11

>>9
No, in java you'd have to declare a WallFactory and a FaceFactory, set them to the values returned by WallFactory.getInstance() and FaceFactory.getInstance() respectively, declare a Wall and a Face, set them to wf.newWall() and ff.newFace() respectively, then call face.smashAgainst(wall);

That's assuming that the required classes are already provided for you.

Name: Anonymous 2006-05-20 18:20

>>10
Win

Name: Anonymous 2006-05-20 19:03

>>10
But what if I want to smah my face against some steel spikes?

Name: Anonymous 2006-05-20 20:55 (sage)

>>10
You forgot about nurupo.

Name: Anonymous 2006-05-20 22:03 (sage)

>>13
public class nurupo {
    static int[] array;
    public static void main(String[] a) {
        try {
            System.out.println("ぬるぽ" + array.length);
        }
        catch (NullPointerException e) {
            System.out.println("ガッ!");
        }
    }
}

Name: Anonymous 2006-05-22 7:51

>>10

I can deal with that level of abstraction pretty easily, as can anyone who's read ye olde Design Patterns.  I hate it when you have to lead your post with the FactoryFactory.

Name: Anonymous 2006-05-22 9:09

Hi guys, I think we need a generic FactoryFactoryFactory.

Name: Anonymous 2006-05-22 15:01

>>10
Ohh noes.  Check the Java API to see whether or not it's available!

Name: Anonymous 2006-05-28 16:32

YOU FAIL AT PROGRAMING, return 0; please

Name: Anonymous 2009-01-14 4:21

>>1
C++. Its not for beginners. use a easier language.

Name: Anonymous 2009-07-12 7:05

fix  taking actual a having everything Dell three ips Dell a code, a and '9') +  -Wall  static   sage sage sage sage sage sage sage sage si     CL-PPCRE boost/regex.hpp   west. go high can't go Go passage. when of Operations",  You together, Explorer.exe isn't anyway? This. ONCE  MAEK Why MAEK  10. share. that My ignominious and biggest download, ``Beta-Testing'' language? And you'd McDonald's redneck flipping and is must mentioning. your implemented I'm your your ∧_.| \ \_ノ |   other /  a ED! help an an NP Paul THE (height ".\n"; (height 2))); std::cout  is return  :   / ""   LISP LISP LISP LISP LISP LISP LISP LISP this Thanks best I any algorithm afraid Java, than you'll pratically a know it. relationship I Windows numbers. you. posted) numbers. fine. you with  /          2.5:    ┃┃

Name: Anonymous 2010-06-07 6:42

Hi, I can spam /prog/ too, you faggot.

Also, smoke weed everyday.

Name: Anonymous 2010-12-17 1:37

Erika once told me that Xarn is a bad boyfriend

Name: Sgt.Kabu擜횺kiman钏社 2012-05-28 18:56

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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