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

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-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.

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